From 48cafc0b6971f7e1ddf3b6b37a66fdf0b3f08a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Tue, 14 Jan 2025 09:51:04 -0800 Subject: [PATCH] Replace $FlowFixMe in StatusBar (#48662) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48662 Changelog: [General][Changed] - Improved types in StatusBar by adding StackProps Reviewed By: javache Differential Revision: D68152452 fbshipit-source-id: a1ec30526e78eb7205e786ae1d0209037e4a0aba --- .../Components/StatusBar/StatusBar.js | 37 +++++++++++++------ .../__snapshots__/public-api-test.js.snap | 25 +++++++++++-- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/packages/react-native/Libraries/Components/StatusBar/StatusBar.js b/packages/react-native/Libraries/Components/StatusBar/StatusBar.js index f3be5e02ad97ce..784b8eeea361d7 100644 --- a/packages/react-native/Libraries/Components/StatusBar/StatusBar.js +++ b/packages/react-native/Libraries/Components/StatusBar/StatusBar.js @@ -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. */ @@ -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 { @@ -203,7 +221,7 @@ function createStackEntry(props: any): any { * `currentHeight` (Android only) The height of the status bar. */ class StatusBar extends React.Component { - static _propsStack: Array = []; + static _propsStack: Array = []; static _defaultProps: any = createStackEntry({ backgroundColor: @@ -218,12 +236,10 @@ class StatusBar extends React.Component { }); // 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. @@ -371,8 +387,7 @@ class StatusBar extends React.Component { 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 @@ -412,14 +427,14 @@ class StatusBar extends React.Component { 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 @@ -456,7 +471,7 @@ class StatusBar extends React.Component { 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. diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index e9573da33c79b1..205551403b9648 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -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 { - static _propsStack: Array; + static _propsStack: Array; 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; @@ -2499,7 +2516,7 @@ declare class StatusBar extends React.Component { 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;