react-native-navbar
react-native-navbar copied to clipboard
Lazy-update status bar
The StatusBar should not be updated every time a prop changes, it
should be updated when one of the visual props changes: style,
hidden or tintColor.
The current aggressive update strategy causes problems in apps with multiple nav bars, since bars on views hidden lower in the route stack can end up operating on the status bar, which is obviously unwanted behavior.
@grabbou @Kureev the functionality change I implemented in this PR ended up causing a regression in my app: status bars no longer automatically update when you pop(). We have a light status bar on main pages that turns black on subpages, and the way the existing component is written it always updated itself on pop() without needing to do anything special to make it update.
To fix, I had to modify NavigationBar again with a forceUpdateToken https://github.com/Instrument/react-native-navbar/commit/e9b13f4235cb6e7f639c38d4697049430bbb8cef
And then in my NavBar hoc, which receives navigator and route props, I added logic to sniff whether the bar's page is at the top of the current route stack:
if (props && props.navigator && props.route
&& props.navigator.getCurrentRoutes().pop().__navigatorRouteID === props.route.__navigatorRouteID) {
this.forceStatusBarUpdateToken++
}
...
<NavigationBar
statusBar= {
forceUpdateToken: this.forceStatusBarUpdateToken,
...
We should consider this problem before you merge this, I don't want to break anyone else's app.
It's kind of a catch-22 since I need all of these changes in our app to avoid the first problem, which was that many buried pages in the stack are all setting the status bar at once on every push() or pop().