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

Swizzle RCTEventDispatcher #4576

Merged
merged 1 commit into from
Jun 16, 2023
Merged

Conversation

tomekzaw
Copy link
Member

@tomekzaw tomekzaw commented Jun 15, 2023

Summary

Reanimated needs to intercept events while still on the UI thread. To achieve this on iOS, currently we overwrite the instance of RCTEventDispatcher with an instance of REAEventDispatcher which extends RCTEventDispatcher but overrides sentEvent method. We need to overwrite event dispatcher as soon as possible, i.e. before native modules are initialized, so that RNGestureHandlerManager holds an already overwritten instance (see here). Currently, we call REAInitializer in jsExecutorFactoryForBridge method. This PR removes some dirty initialization code and uses swizzling instead to achieve the same effect.

screenshot

Test plan

  1. Build Example app on iOS
  2. Check scroll- and gesture-based examples

@tomekzaw tomekzaw requested a review from piaskowyk June 15, 2023 08:15
Copy link
Member

@piaskowyk piaskowyk left a comment

Choose a reason for hiding this comment

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

👍

@tomekzaw tomekzaw added this pull request to the merge queue Jun 16, 2023
Merged via the queue into main with commit af12bd0 Jun 16, 2023
5 checks passed
@tomekzaw tomekzaw deleted the @tomekzaw/ios-swizzle-rcteventdispatcher branch June 16, 2023 07:04
tomekzaw added a commit that referenced this pull request Jun 19, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR fixes a typo introduced by me in #4576.

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->
Latropos pushed a commit that referenced this pull request Jun 20, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

Reanimated needs to intercept events while still on the UI thread. To
achieve this on iOS, currently we overwrite the instance of
`RCTEventDispatcher` with an instance of `REAEventDispatcher` which
extends `RCTEventDispatcher` but overrides `sentEvent` method. We need
to overwrite event dispatcher as soon as possible, i.e. before native
modules are initialized, so that `RNGestureHandlerManager` holds an
already overwritten instance (see
[here](https://github.com/software-mansion/react-native-gesture-handler/blob/9a3b90df0df3e7f85bb06ae7946aea3be95f717c/ios/RNGestureHandlerManager.mm#L62)).
Currently, we call `REAInitializer` in `jsExecutorFactoryForBridge`
method. This PR removes some dirty initialization code and uses
swizzling instead to achieve the same effect.

<img width="1496" alt="screenshot"
src="https://github.com/software-mansion/react-native-reanimated/assets/20516055/86ed7bec-b40a-4f2a-a29a-9e72f511e77e">

## Test plan

1. Build Example app on iOS
2. Check scroll- and gesture-based examples
Latropos pushed a commit that referenced this pull request Jun 20, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR fixes a typo introduced by me in #4576.

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->
@piaskowyk piaskowyk mentioned this pull request Jun 26, 2023
github-merge-queue bot pushed a commit that referenced this pull request Jul 7, 2023
## Summary

Recently, we began rewriting the iOS initialization process. Tomek moved
the injection of JSI bindings to `installTurboModule` (check out
#4523)
and then used swizzling to eliminate the `REAEventDispatcher` (see
#4576).
More context here:
expo/expo#23057 (comment)

This PR removed UIManager overriding by swizzling the `_manageChildren`
and `uiBlockWithLayoutUpdateForRootView` methods. These changes allowed
us to get rid of `RCTAppDelegate+Reanimated`, `UIResponder+Reanimated`,
and `REAInitializer`.

For now, we're gonna leave `REAInitializer` as deprecated for a few more
releases to maintain backward compatibility. But just a heads up, we'll
be removing it in the future.

## Test plan
- I tested building on different react native versions by CI
https://github.com/piaskowyk/reanimated-rn-version-tester/actions/runs/5375166823
- Tested Layout Animations on Example app form main branch.
Latropos pushed a commit that referenced this pull request Jul 13, 2023
## Summary

Recently, we began rewriting the iOS initialization process. Tomek moved
the injection of JSI bindings to `installTurboModule` (check out
#4523)
and then used swizzling to eliminate the `REAEventDispatcher` (see
#4576).
More context here:
expo/expo#23057 (comment)

This PR removed UIManager overriding by swizzling the `_manageChildren`
and `uiBlockWithLayoutUpdateForRootView` methods. These changes allowed
us to get rid of `RCTAppDelegate+Reanimated`, `UIResponder+Reanimated`,
and `REAInitializer`.

For now, we're gonna leave `REAInitializer` as deprecated for a few more
releases to maintain backward compatibility. But just a heads up, we'll
be removing it in the future.

## Test plan
- I tested building on different react native versions by CI
https://github.com/piaskowyk/reanimated-rn-version-tester/actions/runs/5375166823
- Tested Layout Animations on Example app form main branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants