Skip to content

Commit 7c0b735

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Update commands transform to use helper
Summary: This uses a new helper called `dispatchCommand` that now exists on the renderer. This was added to the renderer here: facebook/react#16085 In Paper it calls UIManager.dispatchViewManagerCommand and in Fabric it calls the c++ Fabric UIManager Reviewed By: rickhanlonii Differential Revision: D16578708 fbshipit-source-id: 30f9468a7fd48afb506c0ee49a460b949bc863a1
1 parent e906af1 commit 7c0b735

File tree

3 files changed

+15
-37
lines changed

3 files changed

+15
-37
lines changed

packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap

+4-8
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ type ModuleProps = $ReadOnly<{| ...ViewProps,
2323
const registerGeneratedViewConfig = require('registerGeneratedViewConfig');
2424
2525
const {
26-
UIManager
27-
} = require(\\"react-native\\");
28-
29-
const {
30-
findNodeHandle
31-
} = require(\\"react-native\\");
26+
dispatchCommand
27+
} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\");
3228
3329
const ModuleViewConfig = {
3430
uiViewClassName: 'RCTModule',
@@ -57,11 +53,11 @@ export const __INTERNAL_VIEW_CONFIG = ModuleViewConfig;
5753
export default nativeComponentName;
5854
export const Commands = {
5955
hotspotUpdate(ref, x, y) {
60-
UIManager.dispatchViewManagerCommand(findNodeHandle(ref), UIManager.getViewManagerConfig(\\"RCTModule\\").Commands.hotspotUpdate, [x, y]);
56+
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);
6157
},
6258
6359
scrollTo(ref, y, animated) {
64-
UIManager.dispatchViewManagerCommand(findNodeHandle(ref), UIManager.getViewManagerConfig(\\"RCTModule\\").Commands.scrollTo, [y, animated]);
60+
dispatchCommand(ref, \\"scrollTo\\", [y, animated]);
6561
}
6662
6763
};"

packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -277,28 +277,24 @@ function buildCommands(
277277
return null;
278278
}
279279

280-
imports.add(UIMANAGER_IMPORT);
281-
imports.add('const {findNodeHandle} = require("react-native")');
280+
imports.add(
281+
'const {dispatchCommand} = require("react-native/Libraries/Renderer/shims/ReactNative");',
282+
);
282283

283284
const properties = commands.map(command => {
284285
const commandName = command.name;
285286
const params = command.typeAnnotation.params;
286287

287-
const componentNameLiteral = j.literal(componentName);
288+
const commandNameLiteral = j.literal(commandName);
288289
const commandNameIdentifier = j.identifier(commandName);
289290
const arrayParams = j.arrayExpression(
290291
params.map(param => {
291292
return j.identifier(param.name);
292293
}),
293294
);
294295

295-
const expression = j.template.expression`
296-
UIManager.dispatchViewManagerCommand(
297-
findNodeHandle(ref),
298-
UIManager.getViewManagerConfig(${componentNameLiteral}).Commands.${commandNameIdentifier},
299-
${arrayParams}
300-
)
301-
`;
296+
const expression = j.template
297+
.expression`dispatchCommand(ref, ${commandNameLiteral}, ${arrayParams})`;
302298

303299
const functionParams = params.map(param => {
304300
return j.identifier(param.name);

packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap

+5-19
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ Map {
127127
'use strict';
128128
129129
const registerGeneratedViewConfig = require('registerGeneratedViewConfig');
130-
const {UIManager} = require(\\"react-native\\")
131-
const {findNodeHandle} = require(\\"react-native\\")
130+
const {dispatchCommand} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\");
132131
133132
const CommandNativeComponentViewConfig = {
134133
uiViewClassName: 'CommandNativeComponent',
@@ -145,19 +144,11 @@ export default nativeComponentName;
145144
146145
export const Commands = {
147146
flashScrollIndicators(ref) {
148-
UIManager.dispatchViewManagerCommand(
149-
findNodeHandle(ref),
150-
UIManager.getViewManagerConfig(\\"CommandNativeComponent\\").Commands.flashScrollIndicators,
151-
[]
152-
);
147+
dispatchCommand(ref, \\"flashScrollIndicators\\", []);
153148
},
154149
155150
allTypes(ref, x, message, animated) {
156-
UIManager.dispatchViewManagerCommand(
157-
findNodeHandle(ref),
158-
UIManager.getViewManagerConfig(\\"CommandNativeComponent\\").Commands.allTypes,
159-
[x, message, animated]
160-
);
151+
dispatchCommand(ref, \\"allTypes\\", [x, message, animated]);
161152
}
162153
};
163154
",
@@ -179,8 +170,7 @@ Map {
179170
'use strict';
180171
181172
const registerGeneratedViewConfig = require('registerGeneratedViewConfig');
182-
const {UIManager} = require(\\"react-native\\")
183-
const {findNodeHandle} = require(\\"react-native\\")
173+
const {dispatchCommand} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\");
184174
185175
const CommandNativeComponentViewConfig = {
186176
uiViewClassName: 'CommandNativeComponent',
@@ -200,11 +190,7 @@ export default nativeComponentName;
200190
201191
export const Commands = {
202192
hotspotUpdate(ref, x, y) {
203-
UIManager.dispatchViewManagerCommand(
204-
findNodeHandle(ref),
205-
UIManager.getViewManagerConfig(\\"CommandNativeComponent\\").Commands.hotspotUpdate,
206-
[x, y]
207-
);
193+
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);
208194
}
209195
};
210196
",

0 commit comments

Comments
 (0)