Skip to content

Commit

Permalink
Replace $FlowFixMe in StatusBar (facebook#48662)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#48662

Changelog:
[General][Changed] - Improved types in StatusBar by adding StackProps

Reviewed By: javache

Differential Revision: D68152452

fbshipit-source-id: a1ec30526e78eb7205e786ae1d0209037e4a0aba
  • Loading branch information
coado authored and facebook-github-bot committed Jan 14, 2025
1 parent 6368555 commit 48cafc0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
37 changes: 26 additions & 11 deletions packages/react-native/Libraries/Components/StatusBar/StatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ type Props = $ReadOnly<{|
barStyle?: ?('default' | 'light-content' | 'dark-content'),
|}>;

type StackProps = {
backgroundColor: ?{
value: Props['backgroundColor'],
animated: boolean,
},
barStyle: ?{
value: Props['barStyle'],
animated: boolean,
},
translucent: Props['translucent'],
hidden: ?{
value: boolean,
animated: boolean,
transition: Props['showHideTransition'],
},
networkActivityIndicatorVisible: Props['networkActivityIndicatorVisible'],
};

/**
* Merges the prop stack with the default values.
*/
Expand All @@ -129,7 +147,7 @@ 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): StackProps {
const animated = props.animated ?? false;
const showHideTransition = props.showHideTransition ?? 'fade';
return {
Expand Down Expand Up @@ -203,7 +221,7 @@ function createStackEntry(props: any): any {
* `currentHeight` (Android only) The height of the status bar.
*/
class StatusBar extends React.Component<Props> {
static _propsStack: Array<any> = [];
static _propsStack: Array<StackProps> = [];

static _defaultProps: any = createStackEntry({
backgroundColor:
Expand All @@ -218,12 +236,10 @@ class StatusBar extends React.Component<Props> {
});

// Timer for updating the native module values at the end of the frame.
// $FlowFixMe[missing-local-annot]
static _updateImmediate = null;
static _updateImmediate: ?number = null;

// The current merged values from the props stack.
// $FlowFixMe[missing-local-annot]
static _currentValues = null;
static _currentValues: ?StackProps = null;

// TODO(janic): Provide a real API to deal with status bar height. See the
// discussion in #6195.
Expand Down Expand Up @@ -371,8 +387,7 @@ class StatusBar extends React.Component<Props> {
return newEntry;
}

// $FlowFixMe[missing-local-annot]
_stackEntry = null;
_stackEntry: ?StackProps = null;

componentDidMount() {
// Every time a StatusBar component is mounted, we push it's prop to a stack
Expand Down Expand Up @@ -412,14 +427,14 @@ class StatusBar extends React.Component<Props> {
if (Platform.OS === 'ios') {
if (
!oldProps ||
oldProps.barStyle.value !== mergedProps.barStyle.value
oldProps.barStyle?.value !== mergedProps.barStyle.value
) {
NativeStatusBarManagerIOS.setStyle(
mergedProps.barStyle.value,
mergedProps.barStyle.animated || false,
);
}
if (!oldProps || oldProps.hidden.value !== mergedProps.hidden.value) {
if (!oldProps || oldProps.hidden?.value !== mergedProps.hidden.value) {
NativeStatusBarManagerIOS.setHidden(
mergedProps.hidden.value,
mergedProps.hidden.animated
Expand Down Expand Up @@ -456,7 +471,7 @@ class StatusBar extends React.Component<Props> {
mergedProps.backgroundColor.animated,
);
}
if (!oldProps || oldProps.hidden.value !== mergedProps.hidden.value) {
if (!oldProps || oldProps.hidden?.value !== mergedProps.hidden.value) {
NativeStatusBarManagerAndroid.setHidden(mergedProps.hidden.value);
}
// Activities are not translucent by default, so always set if true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2485,11 +2485,28 @@ type Props = $ReadOnly<{|
animated?: ?boolean,
barStyle?: ?(\\"default\\" | \\"light-content\\" | \\"dark-content\\"),
|}>;
type StackProps = {
backgroundColor: ?{
value: Props[\\"backgroundColor\\"],
animated: boolean,
},
barStyle: ?{
value: Props[\\"barStyle\\"],
animated: boolean,
},
translucent: Props[\\"translucent\\"],
hidden: ?{
value: boolean,
animated: boolean,
transition: Props[\\"showHideTransition\\"],
},
networkActivityIndicatorVisible: Props[\\"networkActivityIndicatorVisible\\"],
};
declare class StatusBar extends React.Component<Props> {
static _propsStack: Array<any>;
static _propsStack: Array<StackProps>;
static _defaultProps: any;
static _updateImmediate: $FlowFixMe;
static _currentValues: $FlowFixMe;
static _updateImmediate: ?number;
static _currentValues: ?StackProps;
static currentHeight: ?number;
static setHidden(hidden: boolean, animation?: StatusBarAnimation): void;
static setBarStyle(style: StatusBarStyle, animated?: boolean): void;
Expand All @@ -2499,7 +2516,7 @@ declare class StatusBar extends React.Component<Props> {
static pushStackEntry(props: any): any;
static popStackEntry(entry: any): void;
static replaceStackEntry(entry: any, props: any): any;
_stackEntry: $FlowFixMe;
_stackEntry: ?StackProps;
componentDidMount(): void;
componentWillUnmount(): void;
componentDidUpdate(): void;
Expand Down

0 comments on commit 48cafc0

Please sign in to comment.