Repository navigation
Per-screen status bar configuration for native tab screens (statusBarStyle, statusBarHidden, statusBarAnimation)
#4888
SimpleCreations
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
Native stack screens can configure the status bar per screen via
statusBarStyle,statusBarHiddenandstatusBarAnimation. The configuration is resolved natively from the visible screen hierarchy, so when a screen is hidden or unmounted, the next visible screen's configuration applies automatically.Native tab screens (
Tabs.Screen) have no equivalent. I'd like to propose adding the same status bar props to tab screens, with the same resolution semantics.Motivation
Moving an app from JS tabs nested in a native stack to native tabs (
@react-navigation/bottom-tabs/unstable), I lost the ability to set the status bar style per tab. Sometimes tabs need different styles, e.g. a transparent header over dark content on one tab and the default style on others.Alternatives today aren't great:
StatusBarmodule (focus-awareStatusBarpattern) can't be combined with screens' status bar props on iOS. Those props requireUIViewControllerBasedStatusBarAppearance = YES, while React Native'sStatusBarmodule requiresNO.My current workaround: from the focused tab, call
navigation.getParent().setOptions({ statusBarStyle })insideuseFocusEffect, so the style is set on the parent native stack screen that hosts the tabs. It works, but every tab has to set the value on focus or it inherits the previous tab's style. It also only works when the tabs are hosted inside a stack screen.Proposed API
Add to
TabsScreenprops, mirroringScreenProps:statusBarStyle?: 'auto' | 'inverted' | 'light' | 'dark'statusBarHidden?: booleanstatusBarAnimation?: 'none' | 'fade' | 'slide'Semantics, matching stack screens:
auto/invertedare unsupported on Android).React Navigation could then expose these as native bottom tab screen options.
Possible implementation path
iOS
RNSTabsScreenComponentViewwith "has set" flags, similarly toRNSScreenView.RNSTabsScreenViewControllermay then implementpreferredStatusBarStyle,prefersStatusBarHiddenandpreferredStatusBarUpdateAnimation. ItschildViewControllerForStatusBarStyle/childViewControllerForStatusBarHiddencould defer to a nested native stack when one provides the trait.findChildVCForConfigAndTraitwould need to pass throughRNSTabBarController, for example by forwarding toselectedViewController. Another option might be a shared "trait provider" abstraction forRNSScreenandRNSTabsScreenViewController. I'm not sure which would fit the existing design better.[RNSScreenWindowTraits updateStatusBarAppearance]on prop changes and on tab selection changes would presumably keep the status bar in sync.Android
TabsScreencould accept the same props.ScreenWindowTraitslookup would need to know about tabs. It could descend from aTabsHostinto the selectedTabsScreenand its nested containers, and fall back from aTabsScreento its ancestors. A shared abstraction forScreenandTabsScreenmight make this simpler.ScreenContainer.setupFragmentManager()about the missing parent-child relationship for containers nested under aFragmentProvidingparent.All reactions