diff --git a/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap b/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap index e53c298d96034b..6258f1f15703ef 100644 --- a/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap +++ b/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap @@ -23,12 +23,8 @@ type ModuleProps = $ReadOnly<{| ...ViewProps, const registerGeneratedViewConfig = require('registerGeneratedViewConfig'); const { - UIManager -} = require(\\"react-native\\"); - -const { - findNodeHandle -} = require(\\"react-native\\"); + dispatchCommand +} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\"); const ModuleViewConfig = { uiViewClassName: 'RCTModule', @@ -57,11 +53,11 @@ export const __INTERNAL_VIEW_CONFIG = ModuleViewConfig; export default nativeComponentName; export const Commands = { hotspotUpdate(ref, x, y) { - UIManager.dispatchViewManagerCommand(findNodeHandle(ref), UIManager.getViewManagerConfig(\\"RCTModule\\").Commands.hotspotUpdate, [x, y]); + dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]); }, scrollTo(ref, y, animated) { - UIManager.dispatchViewManagerCommand(findNodeHandle(ref), UIManager.getViewManagerConfig(\\"RCTModule\\").Commands.scrollTo, [y, animated]); + dispatchCommand(ref, \\"scrollTo\\", [y, animated]); } };" diff --git a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js index 40e5853022ac9a..75b45669fff6ad 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js @@ -277,14 +277,15 @@ function buildCommands( return null; } - imports.add(UIMANAGER_IMPORT); - imports.add('const {findNodeHandle} = require("react-native")'); + imports.add( + 'const {dispatchCommand} = require("react-native/Libraries/Renderer/shims/ReactNative");', + ); const properties = commands.map(command => { const commandName = command.name; const params = command.typeAnnotation.params; - const componentNameLiteral = j.literal(componentName); + const commandNameLiteral = j.literal(commandName); const commandNameIdentifier = j.identifier(commandName); const arrayParams = j.arrayExpression( params.map(param => { @@ -292,13 +293,8 @@ function buildCommands( }), ); - const expression = j.template.expression` - UIManager.dispatchViewManagerCommand( - findNodeHandle(ref), - UIManager.getViewManagerConfig(${componentNameLiteral}).Commands.${commandNameIdentifier}, - ${arrayParams} - ) - `; + const expression = j.template + .expression`dispatchCommand(ref, ${commandNameLiteral}, ${arrayParams})`; const functionParams = params.map(param => { return j.identifier(param.name); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap index 013cb6417d66ff..cd0006dcef6e05 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -127,8 +127,7 @@ Map { 'use strict'; const registerGeneratedViewConfig = require('registerGeneratedViewConfig'); -const {UIManager} = require(\\"react-native\\") -const {findNodeHandle} = require(\\"react-native\\") +const {dispatchCommand} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\"); const CommandNativeComponentViewConfig = { uiViewClassName: 'CommandNativeComponent', @@ -145,19 +144,11 @@ export default nativeComponentName; export const Commands = { flashScrollIndicators(ref) { - UIManager.dispatchViewManagerCommand( - findNodeHandle(ref), - UIManager.getViewManagerConfig(\\"CommandNativeComponent\\").Commands.flashScrollIndicators, - [] - ); + dispatchCommand(ref, \\"flashScrollIndicators\\", []); }, allTypes(ref, x, message, animated) { - UIManager.dispatchViewManagerCommand( - findNodeHandle(ref), - UIManager.getViewManagerConfig(\\"CommandNativeComponent\\").Commands.allTypes, - [x, message, animated] - ); + dispatchCommand(ref, \\"allTypes\\", [x, message, animated]); } }; ", @@ -179,8 +170,7 @@ Map { 'use strict'; const registerGeneratedViewConfig = require('registerGeneratedViewConfig'); -const {UIManager} = require(\\"react-native\\") -const {findNodeHandle} = require(\\"react-native\\") +const {dispatchCommand} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\"); const CommandNativeComponentViewConfig = { uiViewClassName: 'CommandNativeComponent', @@ -200,11 +190,7 @@ export default nativeComponentName; export const Commands = { hotspotUpdate(ref, x, y) { - UIManager.dispatchViewManagerCommand( - findNodeHandle(ref), - UIManager.getViewManagerConfig(\\"CommandNativeComponent\\").Commands.hotspotUpdate, - [x, y] - ); + dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]); } }; ",