-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: only intercept events with waiting handlers #6739
base: main
Are you sure you want to change the base?
Conversation
@mhoran Thanks for the PR. Just making sure if I understand the problem and the proposed solution correctly. Currently, all After this change, the flow described above will be true only for events that pass Is that correct? |
94987fe
to
c7e1976
Compare
Correct. While the Reanimated event listener will bail on events dispatched from the JS thread: react-native-reanimated/packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm Lines 148 to 153 in 254af50
the rotation layout event dispatches from the UI thread. This results in the handler being called with the layout event, which Reanimated intercepts.
Correct. This would ultimately happen when I am not sure what would happen if one were to set up an I added a test for this as well. Triggering a layout event by modifying a view's styles from the UI thread is equivalent to a device rotation (which dispatches on the UI thread.) The test will fail prior to this code change but passes after. |
Thanks for clarification as well as adding the tests.
Sounds like a valid use case, here's a draft PR where I register an event listener for |
c7e1976
to
6784b78
Compare
I've added a test to cover this use case as well. |
6784b78
to
37bac19
Compare
Previously, NativeReanimatedModule::handleRawEvent would intercept all events received by the event listener. This resulted in an issue where onLayout would not fire in JS on the New Architecture. Instead, only intercept events with waiting handlers. This prevents asJSIValue from being called on the Reanimated event loop and allows onLayout to bubble up in JS. See https://github.com/facebook/react-native/blob/v0.76.2/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewEventEmitter.cpp#L82-L112, which prevents onLayout from being dispatched more than once. asJSIValue evaluates the lambda above in https://github.com/facebook/react-native/blob/v0.76.2/packages/react-native/ReactCommon/react/renderer/core/ValueFactoryEventPayload.cpp#L16. Fixes software-mansion#6684
Using notify in the runtime tests would result in test pollution. Reset the notification registry between tests, similar to the call tracker registry.
d72fcbe
to
6adb380
Compare
Summary
Previously, NativeReanimatedModule::handleRawEvent would intercept all events received by the event listener. This resulted in an issue where onLayout would not fire in JS on the New Architecture.
Instead, only intercept events with waiting handlers. This prevents asJSIValue from being called on the Reanimated event loop and allows onLayout to bubble up in JS.
See
https://github.com/facebook/react-native/blob/v0.76.2/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewEventEmitter.cpp#L82-L112, which prevents onLayout from being dispatched more than once.
asJSIValue evaluates the lambda above in
https://github.com/facebook/react-native/blob/v0.76.2/packages/react-native/ReactCommon/react/renderer/core/ValueFactoryEventPayload.cpp#L16.
Fixes #6684
Test plan
See reproducer in #6684. Without this change,
onLayout
will not fire on device rotation. With this change,onLayout
will fire as expected.