11import React , {
22 StyleSheet ,
33 Navigator ,
4- StatusBarIOS ,
54 View ,
65 Platform ,
76 PropTypes ,
87 Text ,
8+ StatusBar ,
99} from 'react-native' ;
1010
1111import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter' ;
1212
1313import NavBarContainer from './components/NavBarContainer' ;
1414import * as Styles from './styles' ;
1515import aspect from 'aspect-js' ;
16+ import _ from 'underscore' ;
1617
1718const propTypes = {
1819 backButtonComponent : PropTypes . func ,
@@ -27,6 +28,7 @@ const propTypes = {
2728 noStatusBar : PropTypes . bool ,
2829 rightCorner : PropTypes . func ,
2930 statusBarColor : PropTypes . string ,
31+ statusBarProps : PropTypes . object ,
3032 titleStyle : Text . propTypes . style ,
3133} ;
3234
@@ -287,16 +289,8 @@ class Router extends React.Component {
287289
288290 render ( ) {
289291 let navigationBar ;
290- // Status bar color
291- if ( Platform . OS === 'ios' ) {
292- if ( this . props . statusBarColor === 'black' ) {
293- StatusBarIOS . setStyle ( 0 ) ; // "Default" style according to StatusBarIOS.js
294- } else {
295- StatusBarIOS . setStyle ( 1 ) ; // "light-content" style according to StatusBarIOS.js
296- }
297- } else if ( Platform . OS === 'android' ) {
298- // no android version yet
299- }
292+ let statusBar ;
293+ let statusBarProps = { } ;
300294
301295 if ( ! this . props . hideNavigationBar ) {
302296 navigationBar = (
@@ -320,14 +314,73 @@ class Router extends React.Component {
320314 ) ;
321315 }
322316
317+ // Check if StatusBar is available (React-Native >= 0.20)
318+ if ( StatusBar ) {
319+ // Check for default values provided to Router
320+ if ( this . props . statusBarProps ) {
321+ // statusBarProps = _.defaults(this.props.statusBarProps, statusBarProps);
322+ statusBarProps = this . props . statusBarProps ;
323+ }
324+
325+ // Check for values provided to current route
326+ if ( this . state . route . statusBarProps ) {
327+ statusBarProps = _ . defaults ( this . state . route . statusBarProps , statusBarProps ) ;
328+ }
329+
330+ // Android specific code
331+ if ( Platform . OS === 'android' ) {
332+ if ( ! _ . has ( statusBarProps , 'backgroundColor' ) && ! _ . has ( statusBarProps , 'translucent' ) ) {
333+ let backgroundColor ;
334+
335+ if ( this . state . route . headerStyle && this . state . router . headerStyle . backgroundColor ) {
336+ // If current route has specific header style
337+ const stateHeaderStyle = StyleSheet . flatten ( this . props . headerStyle ) ;
338+
339+ if ( stateHeaderStyle && stateHeaderStyle . backgroundColor ) {
340+ backgroundColor = stateHeaderStyle . backgroundColor ;
341+ }
342+ } else if ( this . props . headerStyle ) {
343+ // Otherwise, get backgroundColor as specified to Router
344+ const propsHeaderStyle = StyleSheet . flatten ( this . props . headerStyle ) ;
345+
346+ if ( propsHeaderStyle && propsHeaderStyle . backgroundColor ) {
347+ backgroundColor = propsHeaderStyle . backgroundColor ;
348+ }
349+ }
350+
351+ if ( backgroundColor ) {
352+ statusBarProps . backgroundColor = backgroundColor ;
353+ }
354+ }
355+ } else if ( Platform . OS === 'ios' ) {
356+ if ( ! _ . has ( statusBarProps , 'barStyle' ) ) {
357+ // NOTE Deprecated prop, shouldn't be used.
358+ if ( this . props . statusBarColor === 'black' ) {
359+ statusBarProps . barStyle = 'default' ;
360+ } else {
361+ statusBarProps . barStyle = 'light-content' ;
362+ }
363+ }
364+ }
365+
366+ statusBar = (
367+ < StatusBar
368+ { ...statusBarProps }
369+ />
370+ ) ;
371+ }
372+
323373 return (
324- < Navigator
325- ref = "navigator"
326- initialRoute = { this . props . firstRoute }
327- navigationBar = { navigationBar }
328- renderScene = { this . renderScene }
329- configureScene = { this . configureScene }
330- />
374+ < View style = { { flex : 1 } } >
375+ { statusBar }
376+ < Navigator
377+ ref = "navigator"
378+ initialRoute = { this . props . firstRoute }
379+ navigationBar = { navigationBar }
380+ renderScene = { this . renderScene }
381+ configureScene = { this . configureScene }
382+ />
383+ </ View >
331384 ) ;
332385 }
333386}
0 commit comments