44 * This source code is licensed under the MIT license found in the
55 * LICENSE file in the root directory of this source tree.
66 *
7- * @flow
7+ * @flow strict-local
88 * @format
99 */
1010
@@ -101,13 +101,25 @@ export type StatusBarProps = Readonly<{
101101
102102type StackProps = {
103103 barStyle : ?{
104- value : StatusBarProps [ 'barStyle' ] ,
104+ value : StatusBarStyle ,
105105 animated : boolean ,
106106 } ,
107107 hidden : ?{
108108 value : boolean ,
109109 animated : boolean ,
110- transition : StatusBarProps [ 'showHideTransition' ] ,
110+ transition : StatusBarAnimation ,
111+ } ,
112+ } ;
113+
114+ type ResolvedStackProps = {
115+ barStyle : {
116+ value : StatusBarStyle ,
117+ animated : boolean ,
118+ } ,
119+ hidden : {
120+ value : boolean ,
121+ animated : boolean ,
122+ transition : StatusBarAnimation ,
111123 } ,
112124} ;
113125
@@ -126,13 +138,16 @@ function getAutoBarStyle(): 'light-content' | 'dark-content' {
126138 * barStyle to a concrete value.
127139 */
128140function mergePropsStack (
129- propsStack : Array < Object > ,
130- defaultValues : Object ,
131- ) : Object {
132- const merged : StackProps = propsStack . reduce (
141+ propsStack : Array < StackProps > ,
142+ defaultValues : ResolvedStackProps ,
143+ ) : ResolvedStackProps {
144+ const merged : ResolvedStackProps = propsStack . reduce (
133145 ( prev , cur ) => {
134146 for ( const prop in cur ) {
147+ // $FlowFixMe[invalid-computed-prop] dynamic merge over the known StackProps keys
135148 if ( cur [ prop ] != null ) {
149+ // $FlowFixMe[invalid-computed-prop] dynamic merge over the known StackProps keys
150+ // $FlowFixMe[prop-missing] dynamic merge over the known StackProps keys
136151 prev [ prop ] = cur [ prop ] ;
137152 }
138153 }
@@ -141,7 +156,7 @@ function mergePropsStack(
141156 { ...defaultValues } ,
142157 ) ;
143158
144- if ( merged . barStyle ? .value === 'auto' ) {
159+ if ( merged . barStyle . value === 'auto' ) {
145160 merged . barStyle = { ...merged . barStyle , value : getAutoBarStyle ( ) } ;
146161 }
147162
@@ -224,18 +239,18 @@ function createStackEntry(props: StatusBarProps): StackProps {
224239class StatusBar extends React . Component < StatusBarProps > {
225240 static _propsStack : Array < StackProps > = [ ] ;
226241
227- static _defaultProps : any = createStackEntry ( {
228- barStyle : 'default' ,
229- hidden : false ,
230- } ) ;
242+ static _defaultProps : ResolvedStackProps = {
243+ barStyle : { value : 'default' , animated : false } ,
244+ hidden : { value : false , animated : false , transition : 'fade' } ,
245+ } ;
231246
232247 // Timer for updating the native module values at the end of the frame.
233248 static _updateImmediate : ?number = null ;
234249
235250 // The current merged values from the props stack. `barStyle.value` is stored
236251 // in its resolved form (never `'auto'`), so diff comparisons reflect what
237252 // was actually sent to the native module.
238- static _currentValues : ?StackProps = null ;
253+ static _currentValues : ?ResolvedStackProps = null ;
239254
240255 // Number of mounted `StatusBar` instances. Used to lazily subscribe to color
241256 // scheme changes only while at least one instance is on screen.
@@ -264,10 +279,10 @@ class StatusBar extends React.Component<StatusBarProps> {
264279 * changing the status bar hidden property.
265280 */
266281 static setHidden ( hidden : boolean , animation ? : StatusBarAnimation ) {
267- animation = animation || 'none' ;
282+ const resolvedAnimation = animation ?? 'none' ;
268283 StatusBar . _defaultProps . hidden . value = hidden ;
269284 if ( Platform . OS === 'ios' ) {
270- NativeStatusBarManagerIOS . setHidden ( hidden , animation ) ;
285+ NativeStatusBarManagerIOS . setHidden ( hidden , resolvedAnimation ) ;
271286 } else if ( Platform . OS === 'android' ) {
272287 NativeStatusBarManagerAndroid . setHidden ( hidden ) ;
273288 }
@@ -279,11 +294,11 @@ class StatusBar extends React.Component<StatusBarProps> {
279294 * @param animated Animate the style change.
280295 */
281296 static setBarStyle ( style : StatusBarStyle , animated ? : boolean ) {
282- animated = animated || false ;
297+ const resolvedAnimated = animated ?? false ;
283298 StatusBar . _defaultProps . barStyle . value = style ;
284299 const resolvedStyle = style === 'auto' ? getAutoBarStyle ( ) : style ;
285300 if ( Platform . OS === 'ios' ) {
286- NativeStatusBarManagerIOS . setStyle ( resolvedStyle , animated ) ;
301+ NativeStatusBarManagerIOS . setStyle ( resolvedStyle , resolvedAnimated ) ;
287302 } else if ( Platform . OS === 'android' ) {
288303 NativeStatusBarManagerAndroid . setStyle ( resolvedStyle ) ;
289304 }
0 commit comments