Skip to content

Commit

Permalink
Unify and cleanup Platform Flow typing (facebook#38731)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#38731

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D47965692

fbshipit-source-id: ad61acd28a3362b64fa90f413a876c29c1166132
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Aug 3, 2023
1 parent 08688d3 commit 55fd026
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
...props
} = this.props;
const drawStatusBar =
Platform.Version >= 21 && this.props.statusBarBackgroundColor != null;
Platform.OS === 'android' &&
Platform.Version >= 21 &&
this.props.statusBarBackgroundColor != null;
const drawerViewWrapper = (
<View
style={[
Expand Down
14 changes: 6 additions & 8 deletions packages/react-native/Libraries/Utilities/Platform.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
* @flow strict
*/

import NativePlatformConstantsAndroid from './NativePlatformConstantsAndroid';
import type {
Platform as PlatformType,
PlatformSelectSpec,
} from './Platform.flow';

export type PlatformSelectSpec<T> = {
android?: T,
native?: T,
default?: T,
...
};
import NativePlatformConstantsAndroid from './NativePlatformConstantsAndroid';

const Platform = {
const Platform: PlatformType = {
__constants: null,
OS: 'android',
// $FlowFixMe[unsafe-getters-setters]
Expand Down
84 changes: 84 additions & 0 deletions packages/react-native/Libraries/Utilities/Platform.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/

export type PlatformSelectSpec<T> = {
default?: T,
native?: T,
ios?: T,
android?: T,
...
};

type IOSPlatform = {
__constants: null,
OS: $TEMPORARY$string<'ios'>,
// $FlowFixMe[unsafe-getters-setters]
get Version(): string,
// $FlowFixMe[unsafe-getters-setters]
get constants(): {|
forceTouchAvailable: boolean,
interfaceIdiom: string,
isTesting: boolean,
isDisableAnimations?: boolean,
osVersion: string,
reactNativeVersion: {|
major: number,
minor: number,
patch: number,
prerelease: ?number,
|},
systemName: string,
|},
// $FlowFixMe[unsafe-getters-setters]
get isPad(): boolean,
// $FlowFixMe[unsafe-getters-setters]
get isTV(): boolean,
// $FlowFixMe[unsafe-getters-setters]
get isTesting(): boolean,
// $FlowFixMe[unsafe-getters-setters]
get isDisableAnimations(): boolean,
select: <T>(spec: PlatformSelectSpec<T>) => T,
};

type AndroidPlatform = {
__constants: null,
OS: $TEMPORARY$string<'android'>,
// $FlowFixMe[unsafe-getters-setters]
get Version(): number,
// $FlowFixMe[unsafe-getters-setters]
get constants(): {|
isTesting: boolean,
isDisableAnimations?: boolean,
reactNativeVersion: {|
major: number,
minor: number,
patch: number,
prerelease: ?number,
|},
Version: number,
Release: string,
Serial: string,
Fingerprint: string,
Model: string,
ServerHost?: string,
uiMode: string,
Brand: string,
Manufacturer: string,
|},
// $FlowFixMe[unsafe-getters-setters]
get isTV(): boolean,
// $FlowFixMe[unsafe-getters-setters]
get isTesting(): boolean,
// $FlowFixMe[unsafe-getters-setters]
get isDisableAnimations(): boolean,
select: <T>(spec: PlatformSelectSpec<T>) => T,
};

export type Platform = IOSPlatform | AndroidPlatform;
14 changes: 6 additions & 8 deletions packages/react-native/Libraries/Utilities/Platform.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
* @flow strict
*/

import NativePlatformConstantsIOS from './NativePlatformConstantsIOS';
import type {
Platform as PlatformType,
PlatformSelectSpec,
} from './Platform.flow';

export type PlatformSelectSpec<T> = {
default?: T,
native?: T,
ios?: T,
...
};
import NativePlatformConstantsIOS from './NativePlatformConstantsIOS';

const Platform = {
const Platform: PlatformType = {
__constants: null,
OS: 'ios',
// $FlowFixMe[unsafe-getters-setters]
Expand Down

0 comments on commit 55fd026

Please sign in to comment.