-
-
Notifications
You must be signed in to change notification settings - Fork 598
feat(Android, Tabs): handle preventing tab change on Android #3350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,10 @@ class TabsHost( | |
|
|
||
| private var interfaceInsetsChangeListener: SafeAreaView? = null | ||
|
|
||
| // We need to differentiate between user tapping the menu item | ||
| // and update requested from JS. | ||
| private var menuItemSelectedViaContainerUpdate = false | ||
|
|
||
| private val appearanceCoordinator = | ||
| TabsHostAppearanceCoordinator(wrappedContext, bottomNavigationView, tabScreenFragments) | ||
|
|
||
|
|
@@ -221,7 +225,12 @@ class TabsHost( | |
| val fragment = getFragmentForMenuItemId(item.itemId) | ||
| val tabKey = fragment?.tabScreen?.tabKey ?: "undefined" | ||
| eventEmitter.emitOnNativeFocusChange(tabKey) | ||
| true | ||
| if (menuItemSelectedViaContainerUpdate) { | ||
| menuItemSelectedViaContainerUpdate = false | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -317,6 +326,7 @@ class TabsHost( | |
|
|
||
| appearanceCoordinator.updateTabAppearance(this) | ||
|
|
||
| menuItemSelectedViaContainerUpdate = true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call it in updateSelectedTab instead of updateBottomNavigationViewAppearance? It would be a bit more logical there, or these 2 are not always called together ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it as well but I think on Android managing |
||
| bottomNavigationView.selectedItemId = | ||
| checkNotNull(getSelectedTabScreenFragmentId()) { "[RNScreens] A single selected tab must be present" } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing something, or is this supposed to not be triggered when controlledBottomTabs=false, but it is? Also IMO the name is a bit unclear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Android, only controlled bottom tabs are currently supported.
I did use
viaContainerUpdatename because I guess that there is a possibility to call container update from native code, not only as a result of JS focused tab change. I can maybe reverse the logic and usemenuItemSelectedByUseror something like this but I'm not sure.