From 5b527fefcbd98be8dccc6e47f4f726f5fec6ebcf Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Wed, 18 Nov 2020 21:16:22 -0800 Subject: [PATCH] RN: Fix `registerGeneratedViewConfig` Types Summary: Fixes types in `registerGeneratedViewConfig` and also removes some unnecessary hacks for the `ReactNativeViewViewConfig` type. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D25076608 fbshipit-source-id: 5cb2060e11db598b42fbb7f2f8aecfd7f4b262ef --- .../View/ReactNativeViewViewConfig.js | 24 +++++++++++-------- Libraries/Renderer/shims/ReactNativeTypes.js | 4 +++- .../Utilities/registerGeneratedViewConfig.js | 24 +++++++++---------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Libraries/Components/View/ReactNativeViewViewConfig.js b/Libraries/Components/View/ReactNativeViewViewConfig.js index 4d6f0dd0a6c..95cfa81733b 100644 --- a/Libraries/Components/View/ReactNativeViewViewConfig.js +++ b/Libraries/Components/View/ReactNativeViewViewConfig.js @@ -9,15 +9,17 @@ */ 'use strict'; + +import {type ViewConfig} from '../../Renderer/shims/ReactNativeTypes'; import ReactNativeViewViewConfigAndroid from './ReactNativeViewViewConfigAndroid'; import {Platform} from 'react-native'; -const ReactNativeViewConfig = { +const ReactNativeViewConfig: ViewConfig = { uiViewClassName: 'RCTView', baseModuleName: null, Manager: 'ViewManager', - Commands: ({}: {...}), - Constants: ({}: {...}), + Commands: {}, + Constants: {}, bubblingEventTypes: { ...ReactNativeViewViewConfigAndroid.bubblingEventTypes, topBlur: { @@ -171,7 +173,7 @@ const ReactNativeViewConfig = { flexShrink: true, flexWrap: true, height: true, - hitSlop: {diff: (require('../../Utilities/differ/insetsDiffer'): any)}, + hitSlop: {diff: require('../../Utilities/differ/insetsDiffer')}, importantForAccessibility: true, justifyContent: true, left: true, @@ -322,9 +324,10 @@ const ReactNativeViewConfig = { textTransform: true, tintColor: {process: require('../../StyleSheet/processColor')}, top: true, - transform: ((Platform.OS === 'ios' - ? {diff: require('../../Utilities/differ/matricesDiffer')} - : {process: require('../../StyleSheet/processTransform')}): any), + transform: + Platform.OS === 'ios' + ? {diff: require('../../Utilities/differ/matricesDiffer')} + : {process: require('../../StyleSheet/processTransform')}, transformMatrix: true, translateX: true, translateY: true, @@ -334,9 +337,10 @@ const ReactNativeViewConfig = { }, testID: true, top: true, - transform: ((Platform.OS === 'ios' - ? {diff: require('../../Utilities/differ/matricesDiffer')} - : {process: require('../../StyleSheet/processTransform')}): any), + transform: + Platform.OS === 'ios' + ? {diff: require('../../Utilities/differ/matricesDiffer')} + : {process: require('../../StyleSheet/processTransform')}, translateX: true, translateY: true, width: true, diff --git a/Libraries/Renderer/shims/ReactNativeTypes.js b/Libraries/Renderer/shims/ReactNativeTypes.js index 992c762beb1..922585d4c5c 100644 --- a/Libraries/Renderer/shims/ReactNativeTypes.js +++ b/Libraries/Renderer/shims/ReactNativeTypes.js @@ -51,8 +51,10 @@ export type AttributeConfiguration< export type ViewConfig = $ReadOnly<{ Commands?: $ReadOnly<{[commandName: string]: number, ...}>, + Constants?: $ReadOnly<{[name: string]: mixed, ...}>, + Manager?: string, NativeProps?: $ReadOnly<{[propName: string]: string, ...}>, - baseModuleName?: string, + baseModuleName?: ?string, bubblingEventTypes?: $ReadOnly<{ [eventName: string]: $ReadOnly<{ phasedRegistrationNames: $ReadOnly<{ diff --git a/Libraries/Utilities/registerGeneratedViewConfig.js b/Libraries/Utilities/registerGeneratedViewConfig.js index ea25a644421..b8acdb716c4 100644 --- a/Libraries/Utilities/registerGeneratedViewConfig.js +++ b/Libraries/Utilities/registerGeneratedViewConfig.js @@ -23,26 +23,26 @@ function registerGeneratedViewConfig( const staticViewConfig = { uiViewClassName: componentName, Commands: {}, - /* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.122.0 was deployed. To see the error, delete - * this comment and run Flow. */ + // $FlowFixMe[cannot-spread-indexer] Properties can be overridden. bubblingEventTypes: { ...ReactNativeViewViewConfig.bubblingEventTypes, - ...(viewConfig.bubblingEventTypes || {}), + ...(viewConfig.bubblingEventTypes ?? {}: $NonMaybeType< + $PropertyType, + >), }, - /* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.122.0 was deployed. To see the error, delete - * this comment and run Flow. */ + // $FlowFixMe[cannot-spread-indexer] Properties can be overridden. directEventTypes: { ...ReactNativeViewViewConfig.directEventTypes, - ...(viewConfig.directEventTypes || {}), + ...(viewConfig.directEventTypes ?? {}: $NonMaybeType< + $PropertyType, + >), }, - /* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.122.0 was deployed. To see the error, delete - * this comment and run Flow. */ + // $FlowFixMe[cannot-spread-indexer] Properties can be overridden. validAttributes: { ...ReactNativeViewViewConfig.validAttributes, - ...(viewConfig.validAttributes || {}), + ...(viewConfig.validAttributes ?? {}: $NonMaybeType< + $PropertyType, + >), }, };