mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
6974697b04
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42812 There is a way of defining events where you specify additional string type parameter in the EventHandler in the spec. This additional type parameter is an overridden top level event name, that can be completely unrelated to the event handler name. More context here D16042065. Let's say we have ``` onLegacyStyleEvent?: ?BubblingEventHandler<LegacyStyleEvent, 'alternativeLegacyName'> ``` This will produce the following entry in the view config: ``` topAlternativeLegacyName: { phasedRegistrationNames: { captured: 'onLegacyStyleEventCapture', bubbled: 'onLegacyStyleEvent' } } ``` This means that React expects `topAlternativeLegacyName`. But the generated EventEmitter looks like this: ``` void RNTMyNativeViewEventEmitter::onLegacyStyleEvent(OnLegacyStyleEvent $event) const { dispatchEvent("legacyStyleEvent", [$event=std::move($event)](jsi::Runtime &runtime) { auto $payload = jsi::Object(runtime); $payload.setProperty(runtime, "string", $event.string); return $payload; }); } ``` The native component will emit `legacyStyleEvent` (`topLegacyStyleEvent` after normalization) that React will not be able to handle. This issue only happens on iOS because Android doesn't use EventEmitter currently. To address this issue we'll use `paperTopLevelNameDeprecated` for the generated EventEmitters if it is defined. Changelog: [iOS][Fixed] - Fixed support for event name override in component specs. Reviewed By: cortinico, mdvacca, cipolleschi Differential Revision: D53310654 fbshipit-source-id: 018d5b11d8d36e2ecf900b9d8d6fe3e2ed71f80b
@react-native/codegen
Installation
yarn add --dev @react-native/codegen
Note: We're using yarn to install deps. Feel free to change commands to use npm 3+ and npx if you like
Testing
To run the tests in this package, run the following commands from the React Native root folder:
yarnto install the dependencies. You just need to run this onceyarn jest packages/react-native-codegen.