5
5
* LICENSE file in the root directory of this source tree.
6
6
*
7
7
* @format
8
- * @flow strict-local
8
+ * @flow
9
9
*/
10
10
11
11
'use strict' ;
@@ -103,88 +103,53 @@ type Props = $ReadOnly<{|
103
103
barStyle ?: ?( 'default' | 'light-content' | 'dark-content' ) ,
104
104
| } > ;
105
105
106
- type StackEntryProps = { |
107
- /**
108
- * The background color of the status bar.
109
- *
110
- * @platform android
111
- */
112
- backgroundColor : { |
113
- value : ?string ,
114
- animated : ?boolean ,
115
- | } ,
116
- /**
117
- * Sets the color of the status bar text.
118
- */
119
- barStyle : { |
120
- value : ?string ,
121
- animated : ?boolean ,
122
- | } ,
123
- /**
124
- * If the status bar is translucent.
125
- * When translucent is set to true, the app will draw under the status bar.
126
- * This is useful when using a semi transparent status bar color.
127
- */
128
- translucent : ?boolean ,
129
- /**
130
- *
131
- */
132
- hidden : { |
133
- value : ?boolean ,
134
- animated : boolean ,
135
- transition : ?( 'slide ' | 'fade ') ,
136
- | } ,
137
- /**
138
- * If the network activity indicator should be visible.
139
- *
140
- * @platform ios
141
- */
142
- networkActivityIndicatorVisible : ?boolean ,
143
- | } ;
144
-
145
106
/**
146
107
* Merges the prop stack with the default values.
147
108
*/
148
109
function mergePropsStack (
149
- propsStack : $ReadOnlyArray < StackEntryProps > ,
150
- defaultValues : StackEntryProps ,
151
- ) : StackEntryProps {
152
- const init : StackEntryProps = {
153
- ...defaultValues ,
154
- } ;
155
-
110
+ propsStack : Array < Object > ,
111
+ defaultValues : Object ,
112
+ ) : Object {
156
113
return propsStack . reduce ( ( prev , cur ) => {
157
114
for ( const prop in cur ) {
158
115
if ( cur [ prop ] != null ) {
159
116
prev [ prop ] = cur [ prop ] ;
160
117
}
161
118
}
162
119
return prev ;
163
- } , init ) ;
120
+ } , Object . assign ( { } , defaultValues ) ) ;
164
121
}
165
122
166
123
/**
167
124
* Returns an object to insert in the props stack from the props
168
125
* and the transition/animation info.
169
126
*/
170
- function createStackEntry ( props : Props ) : StackEntryProps {
127
+ function createStackEntry ( props : any ) : any {
171
128
return {
172
- backgroundColor : {
173
- value : props . backgroundColor ,
174
- animated : props . animated ,
175
- } ,
176
- barStyle : {
177
- value : props . barStyle ,
178
- animated : props . animated ,
179
- } ,
180
- translucent : props . translucent || false ,
181
- hidden : {
182
- value : props . hidden ,
183
- animated : props . animated || false ,
184
- transition : props . showHideTransition ,
185
- } ,
186
- networkActivityIndicatorVisible :
187
- props . networkActivityIndicatorVisible || false ,
129
+ backgroundColor :
130
+ props . backgroundColor != null
131
+ ? {
132
+ value : props . backgroundColor ,
133
+ animated : props . animated ,
134
+ }
135
+ : null ,
136
+ barStyle :
137
+ props . barStyle != null
138
+ ? {
139
+ value : props . barStyle ,
140
+ animated : props . animated ,
141
+ }
142
+ : null ,
143
+ translucent : props . translucent ,
144
+ hidden :
145
+ props . hidden != null
146
+ ? {
147
+ value : props . hidden ,
148
+ animated : props . animated ,
149
+ transition : props . showHideTransition ,
150
+ }
151
+ : null ,
152
+ networkActivityIndicatorVisible : props . networkActivityIndicatorVisible ,
188
153
} ;
189
154
}
190
155
@@ -228,9 +193,9 @@ function createStackEntry(props: Props): StackEntryProps {
228
193
* `currentHeight` (Android only) The height of the status bar.
229
194
*/
230
195
class StatusBar extends React . Component < Props > {
231
- static _propsStack : Array < StackEntryProps > = [ ] ;
196
+ static _propsStack = [ ] ;
232
197
233
- static _defaultProps : StackEntryProps = createStackEntry ( {
198
+ static _defaultProps = createStackEntry ( {
234
199
animated : false ,
235
200
showHideTransition : 'fade' ,
236
201
backgroundColor : 'black' ,
@@ -265,9 +230,10 @@ class StatusBar extends React.Component<Props> {
265
230
* changing the status bar hidden property.
266
231
*/
267
232
static setHidden ( hidden : boolean , animation ? : StatusBarAnimation ) {
233
+ animation = animation || 'none' ;
268
234
StatusBar . _defaultProps . hidden . value = hidden ;
269
235
if ( Platform . OS === 'ios' ) {
270
- StatusBarManager . setHidden ( hidden , animation || 'none' ) ;
236
+ StatusBarManager . setHidden ( hidden , animation ) ;
271
237
} else if ( Platform . OS === 'android' ) {
272
238
StatusBarManager . setHidden ( hidden ) ;
273
239
}
@@ -279,9 +245,10 @@ class StatusBar extends React.Component<Props> {
279
245
* @param animated Animate the style change.
280
246
*/
281
247
static setBarStyle ( style : StatusBarStyle , animated ?: boolean ) {
248
+ animated = animated || false ;
282
249
StatusBar . _defaultProps . barStyle . value = style ;
283
250
if ( Platform . OS === 'ios' ) {
284
- StatusBarManager . setStyle ( style , animated || false ) ;
251
+ StatusBarManager . setStyle ( style , animated ) ;
285
252
} else if ( Platform . OS === 'android' ) {
286
253
StatusBarManager . setStyle ( style ) ;
287
254
}
@@ -312,8 +279,9 @@ class StatusBar extends React.Component<Props> {
312
279
console . warn ( '`setBackgroundColor` is only available on Android' ) ;
313
280
return ;
314
281
}
282
+ animated = animated || false ;
315
283
StatusBar . _defaultProps . backgroundColor . value = color ;
316
- StatusBarManager . setColor ( processColor ( color ) , animated || false ) ;
284
+ StatusBarManager . setColor ( processColor ( color ) , animated ) ;
317
285
}
318
286
319
287
/**
0 commit comments