titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

Android: experimental BottomNavigation doesn't work with map

Open m1ga opened this issue 7 months ago • 6 comments

I have searched and made sure there are no existing issues for the issue I am filing

  • [x] I have searched the existing issues

Description

We had this for listviews already but the new BottomNavigation also doesn't like the map fragment:

E AndroidRuntime: java.lang.IllegalArgumentException: No view found for id 0x2 (unknown) for fragment SupportMapFragment{80554da} (2f234075-3318-410b-b49b-4da6b0161ade id=0x2)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:559)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:278)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2103)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1998)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1941)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:661)
at android.os.Handler.handleCallback(Handler.java:991)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8934)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

Need to do some more testing. experimental: false will show the tab.

Expected Behavior

show the map

Actual behavior

crash

Reproducible sample

import Map from 'ti.map';

let mapView = Map.createView();
let win1 = Ti.UI.createWindow();
let win2 = Ti.UI.createWindow();
win2.add(mapView);
let tab1 = Ti.UI.createTab({ window: win1, title: '1'});
let tab2 = Ti.UI.createTab({window: win2, title: '2'});
let bottomNav = Ti.UI.createTabGroup({
	tabs: [tab1, tab2],
	theme: "Theme.Titanium.Material3.DayNight",
  experimental: true,
	style: Ti.UI.Android.TABS_STYLE_BOTTOM_NAVIGATION
});
bottomNav.open();

add <module>ti.map</module> and <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> to the <application> node (doesn't need to have a key)

Steps to reproduce

Platform

Android

SDK version you are using

12.7.0.GA

Alloy version you are using

No response

m1ga avatar May 01 '25 17:05 m1ga

@prashantsaini1 do you have any idea what would cause this issue above?

https://github.com/tidev/titanium-sdk/pull/13263/files was an old fix for the same error with a map in a listview header. When I log the fragment id (TiUIFragment.java):

...
fragment = createFragment();
Log.i("---", "ID: " + getId());
transaction.add(getId(), fragment);
...

I do see ID: 1 but it still crashs with No view found for id 0x1 (unknown) for fragment SupportMapFragment. There is something missing in the new BottomNavigation class that works in the none-experimental version.

m1ga avatar May 05 '25 10:05 m1ga

I doubted the same as already fixed in the listview header one. This error usually comes with the Fragment based UI when the view has to be attached before accessing, despite its activity already created. Fragments generally create/destroy views under the same activity. Can you try PROPERTY_FRAGMENT_ONLY being false so the view can wait to be attached?

prashantsaini1 avatar May 05 '25 10:05 prashantsaini1

It should be false by default: https://github.com/tidev/titanium-sdk/blob/db91edf813e8986168452fbb4e6bf49519b776ab/android/titanium/src/java/org/appcelerator/titanium/view/TiUIFragment.java#L24

setting it to true won't crash but won't show a map either.

I'll play around with the onAttachedToWindow method to see if it is an order issue

m1ga avatar May 05 '25 10:05 m1ga

To confirm if it's a view-inflation issue, can you try adding the map-view only when the window is opened? This might be then fixed inside the map module itself.

prashantsaini1 avatar May 05 '25 11:05 prashantsaini1

Tested that already. The window itself is created and normal Ti elements appear. But as soon as I attach the map it will crash with the error above. And only for experimental:true the current bottomNavigation is working.

m1ga avatar May 05 '25 11:05 m1ga

https://github.com/tidev/ti.map/pull/703 as a workaround: map as a normal view instead of a fragment.

m1ga avatar May 16 '25 08:05 m1ga