diff --git a/Libraries/Components/Picker/AndroidDialogPickerViewConfig.js b/Libraries/Components/Picker/AndroidDialogPickerViewConfig.js index 1108b8105e3..44000616369 100644 --- a/Libraries/Components/Picker/AndroidDialogPickerViewConfig.js +++ b/Libraries/Components/Picker/AndroidDialogPickerViewConfig.js @@ -10,7 +10,7 @@ 'use strict'; -import type {GeneratedViewConfig} from '../../Utilities/registerGeneratedViewConfig'; +import type {PartialViewConfig} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes'; const AndroidDialogPickerViewConfig = { uiViewClassName: 'AndroidDialogPicker', @@ -27,4 +27,4 @@ const AndroidDialogPickerViewConfig = { }, }; -module.exports = (AndroidDialogPickerViewConfig: GeneratedViewConfig); +module.exports = (AndroidDialogPickerViewConfig: PartialViewConfig); diff --git a/Libraries/Components/Picker/RCTPickerViewConfig.js b/Libraries/Components/Picker/RCTPickerViewConfig.js index 448bc2a2b8e..9a5ec9d612d 100644 --- a/Libraries/Components/Picker/RCTPickerViewConfig.js +++ b/Libraries/Components/Picker/RCTPickerViewConfig.js @@ -11,7 +11,7 @@ 'use strict'; import ReactNativeViewViewConfig from '../../Components/View/ReactNativeViewViewConfig'; -import type {ReactNativeBaseComponentViewConfig} from '../../Renderer/shims/ReactNativeTypes'; +import {type ViewConfig} from '../../Renderer/shims/ReactNativeTypes'; const RCTPickerViewConfig = { uiViewClassName: 'RCTPicker', @@ -38,4 +38,4 @@ const RCTPickerViewConfig = { }, }; -module.exports = (RCTPickerViewConfig: ReactNativeBaseComponentViewConfig<>); +module.exports = (RCTPickerViewConfig: ViewConfig); diff --git a/Libraries/Components/ScrollView/ScrollViewViewConfig.js b/Libraries/Components/ScrollView/ScrollViewViewConfig.js index b2a3a9246b3..c9603784a85 100644 --- a/Libraries/Components/ScrollView/ScrollViewViewConfig.js +++ b/Libraries/Components/ScrollView/ScrollViewViewConfig.js @@ -10,7 +10,7 @@ 'use strict'; -import type {GeneratedViewConfig} from '../../Utilities/registerGeneratedViewConfig'; +import type {PartialViewConfig} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes'; const ScrollViewViewConfig = { uiViewClassName: 'RCTScrollView', @@ -72,4 +72,4 @@ const ScrollViewViewConfig = { }, }; -module.exports = (ScrollViewViewConfig: GeneratedViewConfig); +module.exports = (ScrollViewViewConfig: PartialViewConfig); diff --git a/Libraries/Components/TextInput/AndroidTextInputViewConfig.js b/Libraries/Components/TextInput/AndroidTextInputViewConfig.js index 0853b60a75d..170a81526dc 100644 --- a/Libraries/Components/TextInput/AndroidTextInputViewConfig.js +++ b/Libraries/Components/TextInput/AndroidTextInputViewConfig.js @@ -11,7 +11,7 @@ 'use strict'; import ReactNativeViewViewConfig from '../../Components/View/ReactNativeViewViewConfig'; -import type {ReactNativeBaseComponentViewConfig} from '../../Renderer/shims/ReactNativeTypes'; +import {type ViewConfig} from '../../Renderer/shims/ReactNativeTypes'; const AndroidTextInputViewConfig = { uiViewClassName: 'AndroidTextInput', @@ -111,4 +111,4 @@ const AndroidTextInputViewConfig = { }, }; -module.exports = (AndroidTextInputViewConfig: ReactNativeBaseComponentViewConfig<>); +module.exports = (AndroidTextInputViewConfig: ViewConfig); diff --git a/Libraries/Components/TextInput/RCTSinglelineTextInputViewConfig.js b/Libraries/Components/TextInput/RCTSinglelineTextInputViewConfig.js index 4836323d1a3..990bcbb1c27 100644 --- a/Libraries/Components/TextInput/RCTSinglelineTextInputViewConfig.js +++ b/Libraries/Components/TextInput/RCTSinglelineTextInputViewConfig.js @@ -11,7 +11,7 @@ 'use strict'; import ReactNativeViewViewConfig from '../../Components/View/ReactNativeViewViewConfig'; -import type {ReactNativeBaseComponentViewConfig} from '../../Renderer/shims/ReactNativeTypes'; +import {type ViewConfig} from '../../Renderer/shims/ReactNativeTypes'; const RCTSinglelineTextInputViewConfig = { uiViewClassName: 'RCTSinglelineTextInputView', @@ -131,4 +131,4 @@ const RCTSinglelineTextInputViewConfig = { }, }; -module.exports = (RCTSinglelineTextInputViewConfig: ReactNativeBaseComponentViewConfig<>); +module.exports = (RCTSinglelineTextInputViewConfig: ViewConfig); diff --git a/Libraries/Image/ImageViewViewConfig.js b/Libraries/Image/ImageViewViewConfig.js index 5870038e97d..4f974c463c2 100644 --- a/Libraries/Image/ImageViewViewConfig.js +++ b/Libraries/Image/ImageViewViewConfig.js @@ -11,7 +11,7 @@ 'use strict'; import ReactNativeViewViewConfig from '../Components/View/ReactNativeViewViewConfig'; -import type {ReactNativeBaseComponentViewConfig} from '../Renderer/shims/ReactNativeTypes'; +import {type ViewConfig} from '../Renderer/shims/ReactNativeTypes'; const ImageViewViewConfig = { uiViewClassName: 'RCTImageView', @@ -65,4 +65,4 @@ const ImageViewViewConfig = { }, }; -module.exports = (ImageViewViewConfig: ReactNativeBaseComponentViewConfig<>); +module.exports = (ImageViewViewConfig: ViewConfig); diff --git a/Libraries/Renderer/shims/ReactNativeTypes.js b/Libraries/Renderer/shims/ReactNativeTypes.js index 2f9876384b8..992c762beb1 100644 --- a/Libraries/Renderer/shims/ReactNativeTypes.js +++ b/Libraries/Renderer/shims/ReactNativeTypes.js @@ -33,10 +33,10 @@ export type MeasureLayoutOnSuccessCallback = ( height: number, ) => void; -type AttributeType = +type AttributeType = | true | $ReadOnly<{| - diff?: (arg1: T, arg2: T) => boolean, + diff?: (arg1: T, arg2: T) => boolean, process?: (arg1: any) => any, |}>; @@ -44,38 +44,40 @@ export type AttributeConfiguration< TProps = string, TStyleProps = string, > = $ReadOnly<{ - [propName: TProps]: AttributeType, - style: $ReadOnly<{[propName: TStyleProps]: AttributeType, ...}>, + [propName: TProps]: AttributeType, + style: $ReadOnly<{[propName: TStyleProps]: AttributeType, ...}>, ... }>; -export type ReactNativeBaseComponentViewConfig< - TProps = string, - TStyleProps = string, -> = $ReadOnly<{| +export type ViewConfig = $ReadOnly<{ + Commands?: $ReadOnly<{[commandName: string]: number, ...}>, + NativeProps?: $ReadOnly<{[propName: string]: string, ...}>, baseModuleName?: string, bubblingEventTypes?: $ReadOnly<{ - [eventName: string]: $ReadOnly<{| - phasedRegistrationNames: $ReadOnly<{| + [eventName: string]: $ReadOnly<{ + phasedRegistrationNames: $ReadOnly<{ captured: string, bubbled: string, - |}>, - |}>, + }>, + }>, ..., }>, - Commands?: $ReadOnly<{[commandName: string]: number, ...}>, directEventTypes?: $ReadOnly<{ - [eventName: string]: $ReadOnly<{| + [eventName: string]: $ReadOnly<{ registrationName: string, - |}>, + }>, ..., }>, - NativeProps?: $ReadOnly<{[propName: string]: string, ...}>, uiViewClassName: string, - validAttributes: AttributeConfiguration, -|}>; + validAttributes: AttributeConfiguration, +}>; -export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig<>; +export type PartialViewConfig = $ReadOnly<{ + bubblingEventTypes?: $PropertyType, + directEventTypes?: $PropertyType, + uiViewClassName: string, + validAttributes?: $ReadOnly<{[propName: string]: AttributeType}>, +}>; export type NativeMethods = { blur(): void, @@ -182,7 +184,7 @@ export type ReactNativeEventTarget = { node: Object, canonical: { _nativeTag: number, - viewConfig: ReactNativeBaseComponentViewConfig<>, + viewConfig: ViewConfig, currentProps: Object, _internalInstanceHandle: Object, ... diff --git a/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js b/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js index 2c09ddf3caa..194a91e31ae 100644 --- a/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +++ b/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js @@ -8,16 +8,10 @@ * @flow strict-local */ -/* eslint-disable react-internal/invariant-args */ - 'use strict'; -import type { - ReactNativeBaseComponentViewConfig, - ViewConfigGetter, -} from './ReactNativeTypes'; - -const invariant = require('invariant'); +import {type ViewConfig} from './ReactNativeTypes'; +import invariant from 'invariant'; // Event configs const customBubblingEventTypes: { @@ -42,9 +36,7 @@ exports.customDirectEventTypes = customDirectEventTypes; const viewConfigCallbacks = new Map(); const viewConfigs = new Map(); -function processEventTypes( - viewConfig: ReactNativeBaseComponentViewConfig<>, -): void { +function processEventTypes(viewConfig: ViewConfig): void { const {bubblingEventTypes, directEventTypes} = viewConfig; if (__DEV__) { @@ -82,7 +74,7 @@ function processEventTypes( * A callback is provided to load the view config from UIManager. * The callback is deferred until the view is actually rendered. */ -exports.register = function(name: string, callback: ViewConfigGetter): string { +exports.register = function(name: string, callback: () => ViewConfig): string { invariant( !viewConfigCallbacks.has(name), 'Tried to register two views with the same name %s', @@ -103,7 +95,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): ViewConfig { let viewConfig; if (!viewConfigs.has(name)) { const callback = viewConfigCallbacks.get(name); diff --git a/Libraries/Renderer/shims/createReactNativeComponentClass.js b/Libraries/Renderer/shims/createReactNativeComponentClass.js index 86a758d918b..f8f4c9284e4 100644 --- a/Libraries/Renderer/shims/createReactNativeComponentClass.js +++ b/Libraries/Renderer/shims/createReactNativeComponentClass.js @@ -11,8 +11,7 @@ 'use strict'; import {ReactNativeViewConfigRegistry} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; - -import type {ViewConfigGetter} from './ReactNativeTypes'; +import {type ViewConfig} from './ReactNativeTypes'; const {register} = ReactNativeViewConfigRegistry; @@ -26,7 +25,7 @@ const {register} = ReactNativeViewConfigRegistry; */ const createReactNativeComponentClass = function( name: string, - callback: ViewConfigGetter, + callback: () => ViewConfig, ): string { return register(name, callback); }; diff --git a/Libraries/Utilities/registerGeneratedViewConfig.js b/Libraries/Utilities/registerGeneratedViewConfig.js index aabcb4989bf..ea25a644421 100644 --- a/Libraries/Utilities/registerGeneratedViewConfig.js +++ b/Libraries/Utilities/registerGeneratedViewConfig.js @@ -10,43 +10,15 @@ 'use strict'; +import {type PartialViewConfig} from '../Renderer/shims/ReactNativeTypes'; import ReactNativeViewConfigRegistry from '../Renderer/shims/ReactNativeViewConfigRegistry'; import ReactNativeViewViewConfig from '../Components/View/ReactNativeViewViewConfig'; import getNativeComponentAttributes from '../ReactNative/getNativeComponentAttributes'; import verifyComponentAttributeEquivalence from './verifyComponentAttributeEquivalence'; -export type GeneratedViewConfig = { - uiViewClassName: string, - bubblingEventTypes?: $ReadOnly<{ - [eventName: string]: $ReadOnly<{| - phasedRegistrationNames: $ReadOnly<{| - captured: string, - bubbled: string, - |}>, - |}>, - ..., - }>, - directEventTypes?: $ReadOnly<{ - [eventName: string]: $ReadOnly<{| - registrationName: string, - |}>, - ..., - }>, - validAttributes?: { - [propName: string]: - | true - | $ReadOnly<{| - diff?: (arg1: any, arg2: any) => boolean, - process?: (arg1: any) => any, - |}>, - ..., - }, - ... -}; - function registerGeneratedViewConfig( componentName: string, - viewConfig: GeneratedViewConfig, + viewConfig: PartialViewConfig, ) { const staticViewConfig = { uiViewClassName: componentName, diff --git a/Libraries/Utilities/verifyComponentAttributeEquivalence.js b/Libraries/Utilities/verifyComponentAttributeEquivalence.js index bb3e2351116..acd459c1e12 100644 --- a/Libraries/Utilities/verifyComponentAttributeEquivalence.js +++ b/Libraries/Utilities/verifyComponentAttributeEquivalence.js @@ -11,7 +11,7 @@ 'use strict'; import ReactNativeViewViewConfig from '../Components/View/ReactNativeViewViewConfig'; -import type {ReactNativeBaseComponentViewConfig} from '../Renderer/shims/ReactNativeTypes'; +import {type ViewConfig} from '../Renderer/shims/ReactNativeTypes'; const IGNORED_KEYS = ['transform', 'hitSlop']; @@ -39,8 +39,8 @@ const IGNORED_KEYS = ['transform', 'hitSlop']; * years from now... */ export default function verifyComponentAttributeEquivalence( - nativeViewConfig: ReactNativeBaseComponentViewConfig<>, - staticViewConfig: ReactNativeBaseComponentViewConfig<>, + nativeViewConfig: ViewConfig, + staticViewConfig: ViewConfig, ) { for (const prop of [ 'validAttributes', @@ -101,7 +101,7 @@ export function lefthandObjectDiff(leftObj: Object, rightObj: Object): Object { } export function getConfigWithoutViewProps( - viewConfig: ReactNativeBaseComponentViewConfig<>, + viewConfig: ViewConfig, propName: string, ): {...} { if (!viewConfig[propName]) {