Skip to content

Commit 76613ec

Browse files
RSNarafacebook-github-bot
authored andcommitted
Generate one Bubbling/Direct event entry when custom top name is provided
Summary: ## Context Inside native ViewConfigs, events are declared using these bubbling/direct EventType maps: ``` { uiViewClassName: '...', bubblingEventTypes: { topFoo: { registrationName: "onFoo" } }, directEventTypes: {}, validAttributes: { }, } ``` **Pattern:** Note that the top name (i.e: topFoo) is just the registration name (i.e: onFoo) but with "on" replaced with "top". On Android, registration names and top names don't have to follow this pattern. The top name can be **anything.** See ReactionsDockView: https://www.internalfb.com/code/fbsource/[c430d46ed69a03a9d9f40cefa335a6d8bb92f8ec]/fbandroid/java/com/facebook/feedback/reactions/ui/overlay/react/ReactionsDockViewManager.java?lines=26-28%2C32-34%2C38 Here, ReactionDismissedEvent.EVENT_NAME is "topDismiss" https://www.internalfb.com/code/fbsource/[c9f92314a5c46e561a831100dab82164808b05d0]/fbandroid/java/com/facebook/feedback/reactions/ui/overlay/react/ReactionDismissedEvent.java?lines=10-11%2C26 And so to provide you the flexibility to specify a custom topName, the codegen supports a customTopName in the direct/bubbling event types: ``` onDismissWithFeedbackReaction: DirectEventHandler<Event, 'topDismiss'>, ``` This generates the two bubbling event type entries in ReactionsDockView: ``` { uiViewClassName: '...', bubblingEventTypes: { // custom top name topDismiss: { registrationName: "onDismissWithFeedbackReaction" }, // what the top name should actually be topDismissWithFeedbackReaction: { registrationName: "onDismissWithFeedbackReaction" } }, directEventTypes: {}, validAttributes: { }, } ``` **The Problem:** The entry created for "topDismissWithFeedbackReaction" is not necessary. This additional entry creates a discrepancy between ReactionsDockView's static ViewConfig and native ViewConfig. Therefore, this diff removes the second unnecessary entry. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D33418730 fbshipit-source-id: 3988ff6906ad1b2e1ef988a19c64d1e042381ab1
1 parent bd7caa6 commit 76613ec

File tree

3 files changed

+4
-35
lines changed

3 files changed

+4
-35
lines changed

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
239239
},
240240
},
241241
242-
topChange: {
243-
phasedRegistrationNames: {
244-
captured: 'onChangeCapture',
245-
bubbled: 'onChange',
246-
},
247-
},
248-
249242
topEnd: {
250243
phasedRegistrationNames: {
251244
captured: 'onEndCapture',
@@ -259,13 +252,6 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
259252
bubbled: 'onEventBubblingWithPaperName',
260253
},
261254
},
262-
263-
topEventBubblingWithPaperName: {
264-
phasedRegistrationNames: {
265-
captured: 'onEventBubblingWithPaperNameCapture',
266-
bubbled: 'onEventBubblingWithPaperName',
267-
},
268-
},
269255
},
270256
271257
directEventTypes: {
@@ -277,17 +263,9 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
277263
registrationName: 'onEventDirectWithPaperName',
278264
},
279265
280-
topEventDirectWithPaperName: {
281-
registrationName: 'onEventDirectWithPaperName',
282-
},
283-
284266
paperBubblingName: {
285267
registrationName: 'onOrientationChange',
286268
},
287-
288-
topOrientationChange: {
289-
registrationName: 'onOrientationChange',
290-
},
291269
},
292270
293271
validAttributes: {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ function buildViewConfig(
254254
bubblingEvents.push(
255255
generateBubblingEventInfo(event, event.paperTopLevelNameDeprecated),
256256
);
257+
} else {
258+
bubblingEvents.push(generateBubblingEventInfo(event));
257259
}
258-
bubblingEvents.push(generateBubblingEventInfo(event));
259260
return bubblingEvents;
260261
}, []);
261262

@@ -278,8 +279,9 @@ function buildViewConfig(
278279
directEvents.push(
279280
generateDirectEventInfo(event, event.paperTopLevelNameDeprecated),
280281
);
282+
} else {
283+
directEvents.push(generateDirectEventInfo(event));
281284
}
282-
directEvents.push(generateDirectEventInfo(event));
283285
return directEvents;
284286
}, []);
285287

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,23 +384,12 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
384384
bubbled: 'onChange',
385385
},
386386
},
387-
388-
topChange: {
389-
phasedRegistrationNames: {
390-
captured: 'onChangeCapture',
391-
bubbled: 'onChange',
392-
},
393-
},
394387
},
395388
396389
directEventTypes: {
397390
paperDirectChange: {
398391
registrationName: 'onDire tChange',
399392
},
400-
401-
topDire tChange: {
402-
registrationName: 'onDire tChange',
403-
},
404393
},
405394
406395
validAttributes: {},

0 commit comments

Comments
 (0)