Commit dd390f5
committed
fix(android, tabs): broaden selectedTab fallback to cover applyDayNightUiMode race
The original patch guarded `updateBottomNavigationViewAppearance` and made
the lookup helpers null-safe, but field testing surfaced a SECOND crash
path that bypasses those guards:
IllegalStateException: [RNScreens] No selected tab present
at TabsContainer.getSelectedTab(TabsContainer.kt:88)
at TabsAppearanceCoordinator.updateTabAppearance(TabsAppearanceCoordinator.kt:21)
at TabsContainer.applyDayNightUiMode(TabsContainer.kt:591)
at TabsContainer.onAttachedToWindow$lambda$11(TabsContainer.kt:271)
at ColorSchemeCoordinator.applyResolvedColorScheme(ColorSchemeCoordinator.kt:108)
at ColorSchemeCoordinator.setup$react_native_screens_release(ColorSchemeCoordinator.kt:73)
at TabsContainer.onAttachedToWindow(TabsContainer.kt:270)
ColorSchemeCoordinator.setup fires the day/night callback as part of
the same onAttachedToWindow window where fragment screenKeys haven't
flushed. The callback reaches updateTabAppearance → selectedTab on a
code path that did not previously touch updateBottomNavigationViewAppearance,
so guarding only that method left this crash unmitigated.
Guard at the source instead: make the `selectedTab` getter fall back
to the first bound fragment when navState.selectedScreenKey does not
resolve. Only throw when no usable fragment exists at all — that is the
genuine programmer error the original `checkNotNull` was meant to
catch.
Semantics:
- Happy path (fragments bound) — unchanged: getFragmentForScreenKey
returns the matching fragment.
- Initial-mount race (selectedScreenKey set, no fragment bound yet) —
fallback to first bound fragment; one frame of marginally-wrong
appearance is far cheaper than a cold-start IllegalStateException
that kills the activity.
- Genuine empty state (tabsModel has zero entries) — checkNotNull
still throws with the same diagnostic message.
Verified on Pixel 9 (Android 16) cold-start with the same minimal
NativeTabs reproduction as the original patch: previously crashed
100% of the time with 'No selected tab present', now starts cleanly.1 parent 97116e9 commit dd390f5
1 file changed
Lines changed: 12 additions & 1 deletion
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
87 | 96 | | |
88 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
89 | 100 | | |
90 | 101 | | |
91 | 102 | | |
| |||
0 commit comments