Skip to content
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

feat: move notifying observers to event dispatcher #44474

Conversation

WoLewicki
Copy link
Contributor

@WoLewicki WoLewicki commented May 8, 2024

Summary:

Based on the discussion starting here: https://discord.com/channels/514829729862516747/1073566663825432587/1237407161991172157, I suggest moving the call to _notifyEventDispatcherObserversOfEvent_DEPRECATED straight to RCTEventDispatcher.mm. It was previously in RCTInstance.mm which is only relevant on bridgeless mode. We want to mimic the behavior of

NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:scrollEvent, @"event", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED"
object:nil
userInfo:userInfo];
but without using currentBridge since it is considered bad practice: software-mansion/react-native-reanimated#5497 (comment).

Changelog:

[IOS] [CHANGED] - Move notifyObservers straight to RCTEventDispatcher.mm.

Test Plan:

See that example with stickyHeaders still works correctly on both bridgeless and bridge mode.

Videos with it on https://github.com/facebook/react-native/blob/deee037c62a7d62a349d34db427b14d3560ddf83/packages/rn-tester/js/examples/FlatList/FlatList-stickyHeaders.js example with more items for visibility:

  • bridgeless:
bridgelessSticky.mov
  • bridge:
bridgeSticky.mov
  • old arch:
oldarchSticky.mov

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels May 8, 2024
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I know it is a bit of a work, but could you add in the test plan a video or something showing that the event is working in all the use cases:

  • Old Architecture
  • New Architecture (with Bridge - for the internal use case)
  • New Architecture (with bridgeless)

Thank you so much!

@WoLewicki
Copy link
Contributor Author

Done ✅

@WoLewicki
Copy link
Contributor Author

One downside I see about it is that we now add the listener on old arch too where it is not used. But it does not seem too problematic I guess?

@cipolleschi
Copy link
Contributor

One downside I see about it is that we now add the listener on old arch too where it is not used. But it does not seem too problematic I guess?

Yeah, if nothing in the Old Architecture fires the RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED event, that's not an issue!

Out of curiosity, have you tried to remove the pestering code here?
Does ScrollView still works properly without it?

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@analysis-bot
Copy link

analysis-bot commented May 8, 2024

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,542,779 +26
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,912,791 -26
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 93c079b
Branch: main

@WoLewicki
Copy link
Contributor Author

Out of curiosity, have you tried to remove the pestering code here?

Forgot about this one, trying it now.

@WoLewicki
Copy link
Contributor Author

Yeah, it works just fine when this line is removed 🚀 I'll remove it then!

@cipolleschi
Copy link
Contributor

/rebase - this comment automatically rebase on top of main

@cipolleschi
Copy link
Contributor

Finally back to this! :D

@github-actions github-actions bot force-pushed the @wolewicki/move-notify-observers-to-event-dispatcher branch from ce87408 to 34c3ac4 Compare May 20, 2024 09:33
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cipolleschi
Copy link
Contributor

/rebase - this comment automatically rebase on top of main

@cipolleschi
Copy link
Contributor

@WoLewicki I need to work a little on this as I cannot land it as it is, due to how the internal system works... is it okay for you?

@WoLewicki
Copy link
Contributor Author

@cipolleschi yeah no problem, as long as we fix the issue 🚀

cipolleschi pushed a commit to cipolleschi/react-native that referenced this pull request Jun 6, 2024
Summary:
Based on the discussion starting here: https://discord.com/channels/514829729862516747/1073566663825432587/1237407161991172157, I suggest moving the call to `_notifyEventDispatcherObserversOfEvent_DEPRECATED` straight to `RCTEventDispatcher.mm`. It was previously in `RCTInstance.mm` which is only relevant on bridgeless mode. We want to mimic the behavior of https://github.com/facebook/react-native/blob/06eea61c19cd730cf0c14a436f042d30791c3f4a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm#L75-L78 but without using `currentBridge` since it is considered bad practice: software-mansion/react-native-reanimated#5497 (comment).

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [CHANGED] - Move `notifyObservers` straight to `RCTEventDispatcher.mm`.

Pull Request resolved: facebook#44474

Test Plan:
See that example with `stickyHeaders` still works correctly on both bridgeless and bridge mode.

Videos with it on https://github.com/facebook/react-native/blob/deee037c62a7d62a349d34db427b14d3560ddf83/packages/rn-tester/js/examples/FlatList/FlatList-stickyHeaders.js example with more items for visibility:

- bridgeless:

https://github.com/facebook/react-native/assets/32481228/8b78104a-226b-466a-9f32-60ba4ec14100

- bridge:

https://github.com/facebook/react-native/assets/32481228/f2ca67cb-578f-45d4-954f-3249c6fa9410

- old arch:

https://github.com/facebook/react-native/assets/32481228/7d642923-ddda-4dd3-8f14-c9982a03bc2e

Differential Revision: D57097880

Reviewed By: javache

Pulled By: cipolleschi
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 7, 2024
@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in f5c888c.

Copy link

github-actions bot commented Jun 7, 2024

This pull request was successfully merged by @WoLewicki in f5c888c.

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants