From f5be89b8b995bd6a6e040ccde83adb22ab4d273c Mon Sep 17 00:00:00 2001 From: Eli White Date: Wed, 22 Aug 2018 12:49:18 -0700 Subject: [PATCH] Require all Android View Attributes are defined in flow prop types Summary: This caught a few flow types that weren't defined for attributes that Android exposes. Ensuring that these stay in sync will be necessary for codegen in the future. Reviewed By: sahrens Differential Revision: D9444165 fbshipit-source-id: 8ee00af7b732c35d7f6befcdf79f77b73eac6a1b --- .../View/ViewNativeComponentAndroidConfig.js | 11 ++++++++++- Libraries/Components/View/ViewPropTypes.js | 17 +++++++++++++++++ Libraries/Renderer/shims/ReactNativeTypes.js | 11 +++++++---- .../shims/ReactNativeViewConfigRegistry.js | 4 ++-- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Libraries/Components/View/ViewNativeComponentAndroidConfig.js b/Libraries/Components/View/ViewNativeComponentAndroidConfig.js index b53932025..b0fdf87f9 100644 --- a/Libraries/Components/View/ViewNativeComponentAndroidConfig.js +++ b/Libraries/Components/View/ViewNativeComponentAndroidConfig.js @@ -14,9 +14,18 @@ const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes'); const processColor = require('processColor'); +import type {ViewProps} from 'ViewPropTypes'; +import type {____ViewStyle_Internal} from 'StyleSheetTypes'; +import type {ReactNativeBaseComponentViewConfig} from 'ReactNativeTypes'; + const colorHandler = {diff: null, process: processColor}; -const ViewNativeComponentAndroidConfig = { +type Config = ReactNativeBaseComponentViewConfig< + $Keys | $Keys<____ViewStyle_Internal>, + $Keys<____ViewStyle_Internal>, +>; + +const ViewNativeComponentAndroidConfig: Config = { bubblingEventTypes: { topChange: { phasedRegistrationNames: { diff --git a/Libraries/Components/View/ViewPropTypes.js b/Libraries/Components/View/ViewPropTypes.js index 377c40bcb..4b901d9fc 100644 --- a/Libraries/Components/View/ViewPropTypes.js +++ b/Libraries/Components/View/ViewPropTypes.js @@ -72,10 +72,27 @@ type GestureResponderEventProps = $ReadOnly<{| onStartShouldSetResponderCapture?: ?Function, |}>; +type AndroidViewProps = $ReadOnly<{| + nativeBackgroundAndroid?: ?Object, + nativeForegroundAndroid?: ?Object, + + /* Deprecated transform prop. Use the transform style prop instead */ + rotation?: empty, + /* Deprecated transform prop. Use the transform style prop instead */ + scaleX?: empty, + /* Deprecated transform prop. Use the transform style prop instead */ + scaleY?: empty, + /* Deprecated transform prop. Use the transform style prop instead */ + translateX?: empty, + /* Deprecated transform prop. Use the transform style prop instead */ + translateY?: empty, +|}>; + export type ViewProps = $ReadOnly<{| ...DirectEventProps, ...GestureResponderEventProps, ...TouchEventProps, + ...AndroidViewProps, // There's no easy way to create a different type if (Platform.isTV): // so we must include TVViewProps diff --git a/Libraries/Renderer/shims/ReactNativeTypes.js b/Libraries/Renderer/shims/ReactNativeTypes.js index 2dce8ce50..1ee89e82d 100644 --- a/Libraries/Renderer/shims/ReactNativeTypes.js +++ b/Libraries/Renderer/shims/ReactNativeTypes.js @@ -51,7 +51,10 @@ type AttributeType = process: ?(arg1: any) => any, |}>; -export type ReactNativeBaseComponentViewConfig = $ReadOnly<{| +export type ReactNativeBaseComponentViewConfig< + TProps = string, + TStyleProps = string, +> = $ReadOnly<{| baseModuleName?: string, bubblingEventTypes?: $ReadOnly<{ [eventName: string]: $ReadOnly<{| @@ -74,14 +77,14 @@ export type ReactNativeBaseComponentViewConfig = $ReadOnly<{| }>, uiViewClassName: string, validAttributes: $ReadOnly<{ - [propName: string]: AttributeType, + [propName: TProps]: AttributeType, style: $ReadOnly<{ - [propName: string]: AttributeType, + [propName: TStyleProps]: AttributeType, }>, }>, |}>; -export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig; +export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig<>; /** * Class only exists for its Flow type. diff --git a/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js b/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js index 1ef2e80e3..cb16c50f5 100644 --- a/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +++ b/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js @@ -30,7 +30,7 @@ const viewConfigCallbacks = new Map(); const viewConfigs = new Map(); function processEventTypes( - viewConfig: ReactNativeBaseComponentViewConfig, + viewConfig: ReactNativeBaseComponentViewConfig<>, ): void { const {bubblingEventTypes, directEventTypes} = viewConfig; @@ -86,7 +86,7 @@ exports.register = function(name: string, callback: ViewConfigGetter): string { * If this is the first time the view has been used, * This configuration will be lazy-loaded from UIManager. */ -exports.get = function(name: string): ReactNativeBaseComponentViewConfig { +exports.get = function(name: string): ReactNativeBaseComponentViewConfig<> { let viewConfig; if (!viewConfigs.has(name)) { const callback = viewConfigCallbacks.get(name);