Skip to content

fix: updateSelectedTab removing unowned fragments#3608

Merged
kkafar merged 1 commit intosoftware-mansion:mainfrom
lukmccall:patch-4
Feb 3, 2026
Merged

fix: updateSelectedTab removing unowned fragments#3608
kkafar merged 1 commit intosoftware-mansion:mainfrom
lukmccall:patch-4

Conversation

@lukmccall
Copy link
Member

Description

Fixes updateSelectedTab removing unowned fragments (fragments that were created by other libraries)

Changes

  • Made sure that the code will only remove TabScreenFragment

Test plan

This change was tested using the new Expo template in the preview version of Expo Go.
Before, the react-native-screens removed the fragment created by expo-dev-menu. With this fix, everything seems to work.


check(requireFragmentManager.fragments.size <= 1) { "[RNScreens] There can be only a single focused tab" }
val oldFocusedTab = requireFragmentManager.fragments.firstOrNull()
val tabFragments = requireFragmentManager.fragments.filterIsInstance<TabScreenFragment>()
Copy link
Contributor

@t0maboro t0maboro Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good, but I'm wondering whether we could use tabScreenFragments and detect it by isFocusedTab, then we'd always operate only on our fragments (on the other hand, RN is becoming the source of truth then, instead of native state, so this might not be valid), cc-ing @kkafar as he has better context for the tabs impl. on Android

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really. tabScreenFragments do hold fragments for all rendered screens, possibly many, while there should be only a single TabScreenFragment of ours attached to the fragment manager. And this is what these assertions are for.

@t0maboro t0maboro requested a review from kkafar February 2, 2026 20:19
Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have potentially similar problems in stack.

Here I guess it is fine right now as a quick-patch.


check(requireFragmentManager.fragments.size <= 1) { "[RNScreens] There can be only a single focused tab" }
val oldFocusedTab = requireFragmentManager.fragments.firstOrNull()
val tabFragments = requireFragmentManager.fragments.filterIsInstance<TabScreenFragment>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really. tabScreenFragments do hold fragments for all rendered screens, possibly many, while there should be only a single TabScreenFragment of ours attached to the fragment manager. And this is what these assertions are for.

@kkafar kkafar merged commit 441e1d8 into software-mansion:main Feb 3, 2026
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants