5
5
* LICENSE file in the root directory of this source tree.
6
6
*
7
7
* @format
8
- * @flow
8
+ * @flow strict-local
9
9
*/
10
10
11
11
'use strict' ;
@@ -103,53 +103,88 @@ 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
+
106
145
/**
107
146
* Merges the prop stack with the default values.
108
147
*/
109
148
function mergePropsStack (
110
- propsStack : Array < Object > ,
111
- defaultValues : Object ,
112
- ) : Object {
149
+ propsStack : $ReadOnlyArray < StackEntryProps > ,
150
+ defaultValues : StackEntryProps ,
151
+ ) : StackEntryProps {
152
+ const init : StackEntryProps = {
153
+ ...defaultValues ,
154
+ } ;
155
+
113
156
return propsStack . reduce ( ( prev , cur ) => {
114
157
for ( const prop in cur ) {
115
158
if ( cur [ prop ] != null ) {
116
159
prev [ prop ] = cur [ prop ] ;
117
160
}
118
161
}
119
162
return prev ;
120
- } , Object . assign ( { } , defaultValues ) ) ;
163
+ } , init ) ;
121
164
}
122
165
123
166
/**
124
167
* Returns an object to insert in the props stack from the props
125
168
* and the transition/animation info.
126
169
*/
127
- function createStackEntry ( props : any ) : any {
170
+ function createStackEntry ( props : Props ) : StackEntryProps {
128
171
return {
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 ,
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 ,
153
188
} ;
154
189
}
155
190
@@ -193,9 +228,9 @@ function createStackEntry(props: any): any {
193
228
* `currentHeight` (Android only) The height of the status bar.
194
229
*/
195
230
class StatusBar extends React . Component < Props > {
196
- static _propsStack = [ ] ;
231
+ static _propsStack : Array < StackEntryProps > = [ ] ;
197
232
198
- static _defaultProps = createStackEntry ( {
233
+ static _defaultProps : StackEntryProps = createStackEntry ( {
199
234
animated : false ,
200
235
showHideTransition : 'fade' ,
201
236
backgroundColor : 'black' ,
@@ -230,10 +265,9 @@ class StatusBar extends React.Component<Props> {
230
265
* changing the status bar hidden property.
231
266
*/
232
267
static setHidden ( hidden : boolean , animation ? : StatusBarAnimation ) {
233
- animation = animation || 'none' ;
234
268
StatusBar . _defaultProps . hidden . value = hidden ;
235
269
if ( Platform . OS === 'ios' ) {
236
- StatusBarManager . setHidden ( hidden , animation ) ;
270
+ StatusBarManager . setHidden ( hidden , animation || 'none' ) ;
237
271
} else if ( Platform . OS === 'android' ) {
238
272
StatusBarManager . setHidden ( hidden ) ;
239
273
}
@@ -245,10 +279,9 @@ class StatusBar extends React.Component<Props> {
245
279
* @param animated Animate the style change.
246
280
*/
247
281
static setBarStyle ( style : StatusBarStyle , animated ? : boolean ) {
248
- animated = animated || false ;
249
282
StatusBar . _defaultProps . barStyle . value = style ;
250
283
if ( Platform . OS === 'ios' ) {
251
- StatusBarManager . setStyle ( style , animated ) ;
284
+ StatusBarManager . setStyle ( style , animated || false ) ;
252
285
} else if ( Platform . OS === 'android' ) {
253
286
StatusBarManager . setStyle ( style ) ;
254
287
}
@@ -279,9 +312,8 @@ class StatusBar extends React.Component<Props> {
279
312
console . warn ( '`setBackgroundColor` is only available on Android' ) ;
280
313
return ;
281
314
}
282
- animated = animated || false ;
283
315
StatusBar . _defaultProps . backgroundColor . value = color ;
284
- StatusBarManager . setColor ( processColor ( color ) , animated ) ;
316
+ StatusBarManager . setColor ( processColor ( color ) , animated || false ) ;
285
317
}
286
318
287
319
/**
0 commit comments