Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #22282 StatusBar.setHidden() error #22451

Closed
wants to merge 7 commits into from
102 changes: 65 additions & 37 deletions Libraries/Components/StatusBar/StatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @flow strict-local
*/

'use strict';
Expand Down Expand Up @@ -103,13 +103,52 @@ type Props = $ReadOnly<{|
barStyle?: ?('default' | 'light-content' | 'dark-content'),
|}>;

type StackEntryProps = {
/**
* The background color of the status bar.
*
* @platform android
*/
backgroundColor: {
value: ?string,
animated: ?boolean,
},
/**
* Sets the color of the status bar text.
*/
barStyle: {
value: ?string,
animated: ?boolean,
},
/**
* If the status bar is translucent.
* When translucent is set to true, the app will draw under the status bar.
* This is useful when using a semi transparent status bar color.
*/
translucent: ?boolean,
/**
*
*/
hidden: {
value: ?boolean,
animated: boolean,
transition: ?('slide' | 'fade'),
},
/**
* If the network activity indicator should be visible.
*
* @platform ios
*/
networkActivityIndicatorVisible: ?boolean,
};

/**
* Merges the prop stack with the default values.
*/
function mergePropsStack(
propsStack: Array<Object>,
defaultValues: Object,
): Object {
propsStack: $ReadOnlyArray<StackEntryProps>,
defaultValues: StackEntryProps,
): StackEntryProps {
return propsStack.reduce((prev, cur) => {
for (const prop in cur) {
if (cur[prop] != null) {
Expand All @@ -124,32 +163,24 @@ function mergePropsStack(
* Returns an object to insert in the props stack from the props
* and the transition/animation info.
*/
function createStackEntry(props: any): any {
function createStackEntry(props: Props): StackEntryProps {
return {
backgroundColor:
props.backgroundColor != null
? {
value: props.backgroundColor,
animated: props.animated,
}
: null,
barStyle:
props.barStyle != null
? {
value: props.barStyle,
animated: props.animated,
}
: null,
translucent: props.translucent,
hidden:
props.hidden != null
? {
value: props.hidden,
animated: props.animated,
transition: props.showHideTransition,
}
: null,
networkActivityIndicatorVisible: props.networkActivityIndicatorVisible,
backgroundColor: {
value: props.backgroundColor,
animated: props.animated,
},
barStyle: {
value: props.barStyle,
animated: props.animated,
},
translucent: props.translucent || false,
hidden: {
value: props.hidden,
animated: props.animated || false,
transition: props.showHideTransition,
},
networkActivityIndicatorVisible:
props.networkActivityIndicatorVisible || false,
};
}

Expand Down Expand Up @@ -195,7 +226,7 @@ function createStackEntry(props: any): any {
class StatusBar extends React.Component<Props> {
static _propsStack = [];

static _defaultProps = createStackEntry({
static _defaultProps: StackEntryProps = createStackEntry({
animated: false,
showHideTransition: 'fade',
backgroundColor: 'black',
Expand Down Expand Up @@ -229,11 +260,10 @@ class StatusBar extends React.Component<Props> {
* @param animation Optional animation when
* changing the status bar hidden property.
*/
static setHidden(hidden: boolean, animation?: StatusBarAnimation) {
animation = animation || 'none';
static setHidden(hidden: boolean = true, animation?: StatusBarAnimation) {
StatusBar._defaultProps.hidden.value = hidden;
if (Platform.OS === 'ios') {
StatusBarManager.setHidden(hidden, animation);
StatusBarManager.setHidden(hidden, animation || 'none');
} else if (Platform.OS === 'android') {
StatusBarManager.setHidden(hidden);
}
Expand All @@ -245,10 +275,9 @@ class StatusBar extends React.Component<Props> {
* @param animated Animate the style change.
*/
static setBarStyle(style: StatusBarStyle, animated?: boolean) {
animated = animated || false;
StatusBar._defaultProps.barStyle.value = style;
if (Platform.OS === 'ios') {
StatusBarManager.setStyle(style, animated);
StatusBarManager.setStyle(style, animated || false);
} else if (Platform.OS === 'android') {
StatusBarManager.setStyle(style);
}
Expand Down Expand Up @@ -279,9 +308,8 @@ class StatusBar extends React.Component<Props> {
console.warn('`setBackgroundColor` is only available on Android');
return;
}
animated = animated || false;
StatusBar._defaultProps.backgroundColor.value = color;
StatusBarManager.setColor(processColor(color), animated);
StatusBarManager.setColor(processColor(color), animated || false);
}

/**
Expand Down

This file was deleted.