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 RCTUIManager #4619

Merged
merged 15 commits into from
Jul 7, 2023
Merged

Swizzle RCTUIManager #4619

merged 15 commits into from
Jul 7, 2023

Conversation

piaskowyk
Copy link
Member

@piaskowyk piaskowyk commented Jun 23, 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

@piaskowyk piaskowyk marked this pull request as ready for review June 26, 2023 07:45
@piaskowyk piaskowyk requested a review from tomekzaw June 26, 2023 07:56
@piaskowyk piaskowyk changed the title UIManager refactor Swizzle RCTUIManager Jun 27, 2023
ios/REAUtils.h Outdated Show resolved Hide resolved
ios/LayoutReanimation/REASwizzledUIManager.mm Outdated Show resolved Hide resolved
if (self = [super init]) {
_animationsManager = animationsManager;
_uiManager = uiManager;
_reaUIManager = self;
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand the need for this whole REASwizzledUIManager class to exists. Also, assigning singletons like that seem a bit risky.

It seem to me that the reason it's been done this way was for the swizzled methods to be able to access _uiManager and _animationsManager fields. I think the former can just be replaced by self as the swizzling concept refers to swapping out implementation of certain methods. The UI manager object will be the same and the swizzled method self will refer to it.

As for the latter field, the best way IMO would be to use category on UIManager class that adds animationsManager property to it using associated object technique (https://nshipster.com/associated-objects/)

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. I've made the changes based on your suggestions 👍. I dumped the singleton and used associated objects with the category instead.
  2. The only reason I created the REASwizzledUIManager class was to keep the swizzled methods separate from the animation manager. I didn't want to put everything into one file. But yeah, if you think it's best, I can move the _manageChildren and _uiBlockWithLayoutUpdateForRootView methods back to the REAAnimationManager class.

@piaskowyk piaskowyk requested a review from kmagiera June 30, 2023 07:18
ios/LayoutReanimation/REASwizzledUIManager.mm Outdated Show resolved Hide resolved
ios/LayoutReanimation/REAAnimationsManager.m Outdated Show resolved Hide resolved
ios/native/REAInitializer.mm Outdated Show resolved Hide resolved
ios/LayoutReanimation/REASwizzledUIManager.mm Outdated Show resolved Hide resolved
@piaskowyk piaskowyk requested a review from tomekzaw July 7, 2023 09:39
Copy link
Member

@tomekzaw tomekzaw left a comment

Choose a reason for hiding this comment

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

Well done! ❤️

@piaskowyk piaskowyk added this pull request to the merge queue Jul 7, 2023
Merged via the queue into main with commit 6f19a36 Jul 7, 2023
5 checks passed
@piaskowyk piaskowyk deleted the @piaskowyk/UIManager-refactor branch July 7, 2023 12:31
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.
github-merge-queue bot pushed a commit that referenced this pull request Aug 4, 2023
## Summary

Fixes
#4631

In #4619
I removed REAInitializer because it is no longer needed. However, some
brownfield apps still use it. This PR adds a mock for REAInitializer to
ensure backward compatibility.

## Test plan

CI
gabrieldonadel added a commit to expo/expo that referenced this pull request Oct 25, 2023
# Why

update vendoring modules for SDK 50 + this will produce way less diffs
when upgrading for react-native 0.73 support

# How

- `et uvm -m react-native-reanimated -c 3.5.4` 
- Updated `EXVersionUtils.mm` given that REAEventDispatcher and
REAUIManager no longer exist
(software-mansion/react-native-reanimated#4619)

# Test Plan

- unversioned expo go + ncl reanimated
- versioned expo go + ncl reanimated

# Checklist

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [x] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [x] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Kudo Chien <kudo@expo.dev>
marklawlor pushed a commit to expo/expo that referenced this pull request Oct 30, 2023
# Why

update vendoring modules for SDK 50 + this will produce way less diffs
when upgrading for react-native 0.73 support

# How

- `et uvm -m react-native-reanimated -c 3.5.4` 
- Updated `EXVersionUtils.mm` given that REAEventDispatcher and
REAUIManager no longer exist
(software-mansion/react-native-reanimated#4619)

# Test Plan

- unversioned expo go + ncl reanimated
- versioned expo go + ncl reanimated

# Checklist

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [x] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [x] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Kudo Chien <kudo@expo.dev>
@tomekzaw tomekzaw mentioned this pull request Feb 18, 2024
github-merge-queue bot pushed a commit that referenced this pull request May 11, 2024
## Summary

In #4619 @piaskowyk removed `REAInitializer` because it was no longer
required.

To avoid a breaking change, in #4880 he restored `REAInitializer` with
no-op implementation for backward compatibility.

This PR removes `REAInitializer` which effectively does nothing since
3.5.0.
 
## Test plan

Build Example app on iOS.
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

3 participants