-
Notifications
You must be signed in to change notification settings - Fork 24.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
Expose UIManager from Scheduler #33545
Conversation
This pull request was exported from Phabricator. Differential Revision: D35314058 |
|
Base commit: aeac6ab |
This pull request was exported from Phabricator. Differential Revision: D35314058 |
Summary: Pull Request resolved: facebook#33545 Differential Revision: D35314058 fbshipit-source-id: fe7a0feb37da3a691735c4315c64c7bc11c0a89d
65c01d4
to
36e50f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR! I've left a couple of comments regarding some details.
void removeListener(std::shared_ptr<EventListener const> listener); | ||
|
||
private: | ||
butter::shared_mutex lock_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
butter::shared_mutex lock_; | |
butter::shared_mutex mutex_; |
I would like to suggest renaming this field to mutex_
so it is consistent with naming in ComponentDescriptorRegistry
, EventQueue
, ShadowNodeFamily
etc. and can be used as std::unique_lock<butter::shared_mutex> lock(mutex_);
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, must be a typo on my end :)
jsi::Runtime &runtime, | ||
const EventTarget *eventTarget, | ||
const std::string &type, | ||
ReactEventPriority priority, | ||
const ValueFactory &payloadFactory) { | ||
if (!eventListeners_.callListeners( | ||
eventTarget, type, priority, payloadFactory)) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to suggest adding a short comment here for future visitors why we return here (because event listeners not only intercept events but can also prevent them from being passed to JS).
const EventTarget *eventTarget, | ||
const std::string &type, | ||
ReactEventPriority priority, | ||
const ValueFactory &payloadFactory)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure, I would like to ask whether it is safe for event listener to invoke payloadFactory
even if it will decide to pass the event to JS?
In such case payloadFactory
may be called twice – first time in event listener and then one more time in UIManagerBinding::dispatchEvent
. (In fact, each event listener may want to call payloadFactory
arbitrary number of times.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it depends on implementations of payload factory, e.g. if it decides to std::move
some memory
From the implementations I saw in the core, it should be safe (usually we just create the value from struct ref or folly::dynamic
)
bool result = true; | ||
for (auto const &listener : eventListeners_) { | ||
result = | ||
result && listener->operator()(eventTarget, type, priority, payloadFactory); | ||
} | ||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand it correctly, all event listeners intercept the event (in the order of registration) and each one of them individually returns a boolean value whether the event should be passed to JS or not. If any of the event listeners returns false
, the event will not be passed to JS.
Also, even if some event listener returns false
(meaning it could handle the event), the rest of event listeners will still be called, which seems fair. (This guarantee will prevent third-party library developers from racing for first place as there is no priority in voting).
I know it's a matter of preference, but personally it makes more sense to me to return true
from event listener if it successfully managed to handle the event (so it doesn't need to be sent to JS) and false
otherwise (meaning it couldn't handle the event so it probably needs to be passed to JS). So we would start from result = false
, use ||
instead of &&
here and don't need !
in Scheduler.cpp
.
Also, a comment on the semantics of the return value from event listener would be helpful for the other developers as well.
BTW I'm not sure but it looks like the syntax without ->operator()
, i.e. listener(eventTarget, type, priority, payloadFactory)
would also work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree on true/false comment, it will be more aligned with platform apis that way
I added the comment for the Event listener internally, but it probably didn't sync to GitHub.
Also about operator()
, it is dereferencing shared pointer here, so just calling the function doesn't work, unfortunately
I could deref it into EventListener const &
and call it that way, but not sure there is a point in doing so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I forgot that it's a shared pointer. In such case (*listener)(eventTarget, type, priority, payloadFactory)
would do, but the original version with ->operator()
is certainly better in terms of explicitness and readability.
This pull request was exported from Phabricator. Differential Revision: D35314058 |
Summary: Pull Request resolved: facebook#33545 Exposes `UIManager` instance for access from third-party modules. Changelog: [Changed] Exposes `UIManager` instance for third-party access. Differential Revision: D35314058 fbshipit-source-id: 90752fb57c662b78d5355b84f35221d7050e810a
36e50f2
to
fd4bec1
Compare
Base commit: aeac6ab |
@ShikaSD We have just tried out this PR in Fabric version of react-native-reanimated. The good news is that we managed to implement and install a custom event listener on iOS (although we had some difficulties with obtaining a reference to The bad news is that unfortunately I've overlooked the fact that the proposed event listeners are called on the JS thread, after the events are flushed from Can you please let us know if it would be possible to tweak this PR so we can handle the events still on the UI thread? |
Summary: Exposes event listener through iOS scheduler wrapper (`RCTScheduler`) and exposes scheduler itself through `RCTSurfacePresenter`. Changelog: [Changed] Exposed `RCTScheduler` to allow setting event listeners. Differential Revision: D35313398 fbshipit-source-id: 67d27969d7a64f021810292f84ddb52484c11b68
Summary: Minimal set of changes to intercept events in external modules. Current intended use-case is for Reanimated to handle events for the Animated properties. Changelog: [Added] Add listeners to allow intercepting events in C++ core. Differential Revision: D35312534 fbshipit-source-id: 17ea760d016e68ee203b0106a113006f39fc159b
Differential Revision: D35313399 fbshipit-source-id: d53d9642ae351360b5825d280f4244ce701eebcd
Summary: Pull Request resolved: facebook#33545 Exposes `UIManager` instance for access from third-party modules. Changelog: [Changed] Exposes `UIManager` instance for third-party access. Reviewed By: javache Differential Revision: D35314058 fbshipit-source-id: 8640911c24a19c48fe6a4141cfec26c9427fb9c3
This pull request was exported from Phabricator. Differential Revision: D35314058 |
fd4bec1
to
2c6211c
Compare
Summary: Pull Request resolved: facebook#33545 Exposes `UIManager` instance for access from third-party modules. Changelog: [Changed] Exposes `UIManager` instance for third-party access. Differential Revision: D35314058 fbshipit-source-id: b80c5520185f272f66788c3392eccecbb2eb1def
This pull request was successfully merged by @cortinico in 54db5f2. When will my fix make it into a release? | Upcoming Releases |
Summary: Pull Request resolved: facebook#33545 Exposes `UIManager` instance for access from third-party modules. Changelog: [Changed] Exposes `UIManager` instance for third-party access. Reviewed By: javache Differential Revision: D35314058 fbshipit-source-id: 1922c2afc37b105b153a82f45e5bac9c0b0cdfae
Summary: Pull Request resolved: facebook#33545 Exposes `UIManager` instance for access from third-party modules. Changelog: [Changed] Exposes `UIManager` instance for third-party access. Reviewed By: javache Differential Revision: D35314058 fbshipit-source-id: 1922c2afc37b105b153a82f45e5bac9c0b0cdfae Co-authored-by: Nicola Corti <ncor@fb.com>
Summary: Pull Request resolved: facebook#33545 Exposes `UIManager` instance for access from third-party modules. Changelog: [Changed] Exposes `UIManager` instance for third-party access. Reviewed By: javache Differential Revision: D35314058 fbshipit-source-id: 1922c2afc37b105b153a82f45e5bac9c0b0cdfae Co-authored-by: Nicola Corti <ncor@fb.com>
Summary: Pull Request resolved: facebook#33545 Exposes `UIManager` instance for access from third-party modules. Changelog: [Changed] Exposes `UIManager` instance for third-party access. Reviewed By: javache Differential Revision: D35314058 fbshipit-source-id: 1922c2afc37b105b153a82f45e5bac9c0b0cdfae Co-authored-by: Nicola Corti <ncor@fb.com>
Summary: Pull Request resolved: facebook#33545 Exposes `UIManager` instance for access from third-party modules. Changelog: [Changed] Exposes `UIManager` instance for third-party access. Reviewed By: javache Differential Revision: D35314058 fbshipit-source-id: 1922c2afc37b105b153a82f45e5bac9c0b0cdfae Co-authored-by: Nicola Corti <ncor@fb.com>
Differential Revision: D35314058