react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Use paperTopLevelNameDeprecated in generated EventEmitters if defined

Open dmytrorykun opened this issue 1 year ago • 4 comments

Summary: 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.

Differential Revision: D53310654

dmytrorykun avatar Feb 02 '24 13:02 dmytrorykun

This pull request was exported from Phabricator. Differential Revision: D53310654

facebook-github-bot avatar Feb 02 '24 13:02 facebook-github-bot

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 17,246,949 +2
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 20,609,338 -12
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 4d07aae7efacf758967e12472f8d9f1f803c5238 Branch: main

analysis-bot avatar Feb 02 '24 13:02 analysis-bot

This pull request was exported from Phabricator. Differential Revision: D53310654

facebook-github-bot avatar Feb 02 '24 16:02 facebook-github-bot

This pull request was exported from Phabricator. Differential Revision: D53310654

facebook-github-bot avatar Feb 05 '24 11:02 facebook-github-bot

This pull request was exported from Phabricator. Differential Revision: D53310654

facebook-github-bot avatar Feb 12 '24 08:02 facebook-github-bot

This pull request has been merged in facebook/react-native@6974697b049eff0038a17e3ebf962ec7451a5aa4.

facebook-github-bot avatar Feb 13 '24 12:02 facebook-github-bot

While preparing react-native-screens release to work in bridgeless mode I encountered this error on Fabric when bridgeless is disabled. Is this PR the reason why it is appearing?

I can provide a repro if needed.

Screenshot 2024-03-21 at 12 01 55

tjzel avatar Mar 21 '24 11:03 tjzel

While preparing react-native-screens release to work in bridgeless mode I encountered this error on Fabric when bridgeless is disabled. Is this PR the reason why it is appearing?

I can provide a repro if needed.

Are you on a older version of react-native-safe-area-context by any chance?

cortinico avatar Mar 21 '24 11:03 cortinico

Yeah, it was it 😅 On rc1 of screens all is well!

tjzel avatar Mar 21 '24 12:03 tjzel