Skip to content

Commit b060fbe

Browse files
coadofacebook-github-bot
authored andcommitted
Add StatusBar to buildTypes and align Flow with TS types (facebook#49598)
Summary: Pull Request resolved: facebook#49598 Changelog: [Internal] - Added StatusBar to buildTypes and aligned Flow with TS types Reviewed By: huntie Differential Revision: D69990300 fbshipit-source-id: 684c3692fd3cc4862fd3cd3fe4731129887b9bcc
1 parent 4e7b77e commit b060fbe

File tree

3 files changed

+55
-37
lines changed

3 files changed

+55
-37
lines changed

packages/react-native/Libraries/Components/StatusBar/StatusBar.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export type StatusBarAnimation = $Keys<{
5555
...
5656
}>;
5757

58-
type AndroidProps = $ReadOnly<{
58+
export type StatusBarPropsAndroid = $ReadOnly<{
5959
/**
6060
* The background color of the status bar.
6161
* @platform android
@@ -71,7 +71,7 @@ type AndroidProps = $ReadOnly<{
7171
translucent?: ?boolean,
7272
}>;
7373

74-
type IOSProps = $ReadOnly<{
74+
export type StatusBarPropsIOS = $ReadOnly<{
7575
/**
7676
* If the network activity indicator should be visible.
7777
*
@@ -87,9 +87,7 @@ type IOSProps = $ReadOnly<{
8787
showHideTransition?: ?('fade' | 'slide' | 'none'),
8888
}>;
8989

90-
type Props = $ReadOnly<{
91-
...AndroidProps,
92-
...IOSProps,
90+
type StatusBarBaseProps = $ReadOnly<{
9391
/**
9492
* If the status bar is hidden.
9593
*/
@@ -105,22 +103,28 @@ type Props = $ReadOnly<{
105103
barStyle?: ?('default' | 'light-content' | 'dark-content'),
106104
}>;
107105

106+
export type StatusBarProps = $ReadOnly<{
107+
...StatusBarPropsAndroid,
108+
...StatusBarPropsIOS,
109+
...StatusBarBaseProps,
110+
}>;
111+
108112
type StackProps = {
109113
backgroundColor: ?{
110-
value: Props['backgroundColor'],
114+
value: StatusBarProps['backgroundColor'],
111115
animated: boolean,
112116
},
113117
barStyle: ?{
114-
value: Props['barStyle'],
118+
value: StatusBarProps['barStyle'],
115119
animated: boolean,
116120
},
117-
translucent: Props['translucent'],
121+
translucent: StatusBarProps['translucent'],
118122
hidden: ?{
119123
value: boolean,
120124
animated: boolean,
121-
transition: Props['showHideTransition'],
125+
transition: StatusBarProps['showHideTransition'],
122126
},
123-
networkActivityIndicatorVisible: Props['networkActivityIndicatorVisible'],
127+
networkActivityIndicatorVisible: StatusBarProps['networkActivityIndicatorVisible'],
124128
};
125129

126130
/**
@@ -147,7 +151,7 @@ function mergePropsStack(
147151
* Returns an object to insert in the props stack from the props
148152
* and the transition/animation info.
149153
*/
150-
function createStackEntry(props: Props): StackProps {
154+
function createStackEntry(props: StatusBarProps): StackProps {
151155
const animated = props.animated ?? false;
152156
const showHideTransition = props.showHideTransition ?? 'fade';
153157
return {
@@ -220,7 +224,7 @@ function createStackEntry(props: Props): StackProps {
220224
*
221225
* `currentHeight` (Android only) The height of the status bar.
222226
*/
223-
class StatusBar extends React.Component<Props> {
227+
class StatusBar extends React.Component<StatusBarProps> {
224228
static _propsStack: Array<StackProps> = [];
225229

226230
static _defaultProps: any = createStackEntry({
@@ -309,7 +313,7 @@ class StatusBar extends React.Component<Props> {
309313
* @param color Background color.
310314
* @param animated Animate the style change.
311315
*/
312-
static setBackgroundColor(color: string, animated?: boolean): void {
316+
static setBackgroundColor(color: ColorValue, animated?: boolean): void {
313317
if (Platform.OS !== 'android') {
314318
console.warn('`setBackgroundColor` is only available on Android');
315319
return;
@@ -320,7 +324,7 @@ class StatusBar extends React.Component<Props> {
320324
const processedColor = processColor(color);
321325
if (processedColor == null) {
322326
console.warn(
323-
`\`StatusBar.setBackgroundColor\`: Color ${color} parsed to null or undefined`,
327+
`\`StatusBar.setBackgroundColor\`: Color ${String(color)} parsed to null or undefined`,
324328
);
325329
return;
326330
}
@@ -351,7 +355,7 @@ class StatusBar extends React.Component<Props> {
351355
*
352356
* @param props Object containing the StatusBar props to use in the stack entry.
353357
*/
354-
static pushStackEntry(props: any): any {
358+
static pushStackEntry(props: StatusBarProps): StackProps {
355359
const entry = createStackEntry(props);
356360
StatusBar._propsStack.push(entry);
357361
StatusBar._updatePropsStack();
@@ -363,7 +367,7 @@ class StatusBar extends React.Component<Props> {
363367
*
364368
* @param entry Entry returned from `pushStackEntry`.
365369
*/
366-
static popStackEntry(entry: any) {
370+
static popStackEntry(entry: StackProps) {
367371
const index = StatusBar._propsStack.indexOf(entry);
368372
if (index !== -1) {
369373
StatusBar._propsStack.splice(index, 1);
@@ -377,7 +381,10 @@ class StatusBar extends React.Component<Props> {
377381
* @param entry Entry returned from `pushStackEntry` to replace.
378382
* @param props Object containing the StatusBar props to use in the replacement stack entry.
379383
*/
380-
static replaceStackEntry(entry: any, props: any): any {
384+
static replaceStackEntry(
385+
entry: StackProps,
386+
props: StatusBarProps,
387+
): StackProps {
381388
const newEntry = createStackEntry(props);
382389
const index = StatusBar._propsStack.indexOf(entry);
383390
if (index !== -1) {
@@ -400,14 +407,18 @@ class StatusBar extends React.Component<Props> {
400407
componentWillUnmount() {
401408
// When a StatusBar is unmounted, remove itself from the stack and update
402409
// the native bar with the next props.
403-
StatusBar.popStackEntry(this._stackEntry);
410+
if (this._stackEntry != null) {
411+
StatusBar.popStackEntry(this._stackEntry);
412+
}
404413
}
405414

406415
componentDidUpdate() {
407-
this._stackEntry = StatusBar.replaceStackEntry(
408-
this._stackEntry,
409-
this.props,
410-
);
416+
if (this._stackEntry != null) {
417+
this._stackEntry = StatusBar.replaceStackEntry(
418+
this._stackEntry,
419+
this.props,
420+
);
421+
}
411422
}
412423

413424
/**

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,48 +2131,54 @@ export type StatusBarAnimation = $Keys<{
21312131
slide: string,
21322132
...
21332133
}>;
2134-
type AndroidProps = $ReadOnly<{
2134+
export type StatusBarPropsAndroid = $ReadOnly<{
21352135
backgroundColor?: ?ColorValue,
21362136
translucent?: ?boolean,
21372137
}>;
2138-
type IOSProps = $ReadOnly<{
2138+
export type StatusBarPropsIOS = $ReadOnly<{
21392139
networkActivityIndicatorVisible?: ?boolean,
21402140
showHideTransition?: ?(\\"fade\\" | \\"slide\\" | \\"none\\"),
21412141
}>;
2142-
type Props = $ReadOnly<{
2143-
...AndroidProps,
2144-
...IOSProps,
2142+
type StatusBarBaseProps = $ReadOnly<{
21452143
hidden?: ?boolean,
21462144
animated?: ?boolean,
21472145
barStyle?: ?(\\"default\\" | \\"light-content\\" | \\"dark-content\\"),
21482146
}>;
2147+
export type StatusBarProps = $ReadOnly<{
2148+
...StatusBarPropsAndroid,
2149+
...StatusBarPropsIOS,
2150+
...StatusBarBaseProps,
2151+
}>;
21492152
type StackProps = {
21502153
backgroundColor: ?{
2151-
value: Props[\\"backgroundColor\\"],
2154+
value: StatusBarProps[\\"backgroundColor\\"],
21522155
animated: boolean,
21532156
},
21542157
barStyle: ?{
2155-
value: Props[\\"barStyle\\"],
2158+
value: StatusBarProps[\\"barStyle\\"],
21562159
animated: boolean,
21572160
},
2158-
translucent: Props[\\"translucent\\"],
2161+
translucent: StatusBarProps[\\"translucent\\"],
21592162
hidden: ?{
21602163
value: boolean,
21612164
animated: boolean,
2162-
transition: Props[\\"showHideTransition\\"],
2165+
transition: StatusBarProps[\\"showHideTransition\\"],
21632166
},
2164-
networkActivityIndicatorVisible: Props[\\"networkActivityIndicatorVisible\\"],
2167+
networkActivityIndicatorVisible: StatusBarProps[\\"networkActivityIndicatorVisible\\"],
21652168
};
2166-
declare class StatusBar extends React.Component<Props> {
2169+
declare class StatusBar extends React.Component<StatusBarProps> {
21672170
static currentHeight: ?number;
21682171
static setHidden(hidden: boolean, animation?: StatusBarAnimation): void;
21692172
static setBarStyle(style: StatusBarStyle, animated?: boolean): void;
21702173
static setNetworkActivityIndicatorVisible(visible: boolean): void;
2171-
static setBackgroundColor(color: string, animated?: boolean): void;
2174+
static setBackgroundColor(color: ColorValue, animated?: boolean): void;
21722175
static setTranslucent(translucent: boolean): void;
2173-
static pushStackEntry(props: any): any;
2174-
static popStackEntry(entry: any): void;
2175-
static replaceStackEntry(entry: any, props: any): any;
2176+
static pushStackEntry(props: StatusBarProps): StackProps;
2177+
static popStackEntry(entry: StackProps): void;
2178+
static replaceStackEntry(
2179+
entry: StackProps,
2180+
props: StatusBarProps
2181+
): StackProps;
21762182
componentDidMount(): void;
21772183
componentWillUnmount(): void;
21782184
componentDidUpdate(): void;

scripts/build/build-types/buildTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const ENTRY_POINTS = [
7171
'packages/react-native/Libraries/Components/Touchable/TouchableNativeFeedback.js',
7272
'packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js',
7373
'packages/react-native/Libraries/Components/Switch/Switch.js',
74+
'packages/react-native/Libraries/Components/StatusBar/StatusBar.js',
7475
];
7576

7677
/**

0 commit comments

Comments
 (0)