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

Make Fabric event receivers init only once #6907

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we somehow move the event subscription bits to the same place in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tjzel we could. Here, I targeted only the given problem without taking any risk in refactoring the code, so I believe we could do that in a seperate PR 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's a major refactor then leave it since we don't want to put too much effort into refactoring Paper code. If it's minor we could include it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll see about it, but they are being initialized from two different contexts - paper goes through the usual initializer, fabric gets a initiWithContext method, sounds fishy

Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,20 @@ protected void doFrameGuarded(long frameTimeNanos) {
}
};

// We register as event listener at the end, because we pass `this` and we haven't finished
// constructing an object yet.
// This lead to a crash described in
// https://github.com/software-mansion/react-native-reanimated/issues/604 which was caused by
// Nodes Manager being constructed on UI thread and registering for events.
// Events are handled in the native modules thread in the `onEventDispatch()` method.
// This method indirectly uses `mChoreographerCallback` which was created after event
// registration, creating race condition
EventDispatcher eventDispatcher =
Objects.requireNonNull(UIManagerHelper.getEventDispatcher(context, uiManagerType));
eventDispatcher.addListener(this);
mUnsubscribe = () -> eventDispatcher.removeListener(this);
if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// We register as event listener at the end, because we pass `this` and we haven't finished
// constructing an object yet.
// This lead to a crash described in
// https://github.com/software-mansion/react-native-reanimated/issues/604 which was caused by
// Nodes Manager being constructed on UI thread and registering for events.
// Events are handled in the native modules thread in the `onEventDispatch()` method.
// This method indirectly uses `mChoreographerCallback` which was created after event
// registration, creating race condition
EventDispatcher eventDispatcher =
Objects.requireNonNull(UIManagerHelper.getEventDispatcher(context, uiManagerType));
eventDispatcher.addListener(this);
mUnsubscribe = () -> eventDispatcher.removeListener(this);
}

mAnimationManager = new AnimationsManager(mContext, mUIManager);
}
Expand Down
Loading