-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Allow again for injecting custom root view via ReactActivityDelegate #26495
Allow again for injecting custom root view via ReactActivityDelegate #26495
Conversation
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.
LGTM, thanks for fixing this @kmagiera
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.
@mdvacca is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
This pull request was successfully merged by @kmagiera in 9f0dede. When will my fix make it into a release? | Upcoming Releases |
…26495) Summary: This change restores the possibility of injecting custom root views via ReactAcitivtyDelegate. It has been used by react-native-gesture-handler library in order to replace default root view with a one that'd route touch events to gesture-handler internal pipeline. The regression happened in d0792d4 where new `ReactDelegate` was introduced to provide support for rendering react native views in both Android fragments and activities. As a part of that change the logic responsible for creating root view has been moved from `ReactActivityDelegate` to `ReactDelegate` rendering `ReactActivityDelegate.createRootView` unused – that is there is no code path that leads to this method being called. Instead `ReactDelegate.createRootView` method has been added which now plays the same role. The custom root view injection was relying on overwriting that method and hence the method is no longer referenced overwriting it has no effect. Following the logic migration out of `ReactActivityDelegate` into `ReactDelegate` we could potentially now start overwriting methods of `ReactDelegate`. However when working with Android's activities in React Native we can only provide an instance of `ReactActivityDelegate` and in my opinion it does not make too much sense to expose also a way to provide own instance of `ReactDelegate`. The proposed fix was to route `ReactDelegate.createRootView` to call `ReactActivityDelegate.createRootView` and this way regaining control over root view creation to `ReactActivityDelgate`. The change of the behavior has been implemented by subclassing `ReactDelegate` directly from `ReactActivityDelegate` and hooking the aforementioned methods together. Thanks to this approach, the change has no effect on `ReactDelegate` being used directly from fragments or in other scenarios where it is not being instantiated from `ReactActivityDelegate`. This fixes an issue reported in software-mansion/react-native-gesture-handler#745 and discussed on 0.61 release thread: react-native-community/releases#140 (comment) ## Changelog [Internal] [Fixed] - Allow for custom root view to be injected via ReactActivityDelegate Pull Request resolved: #26495 Test Plan: 1. Run RNTester, take layout snapshot, see the react root view being on the top of view hierarchy. 2. Run gesture-handler Example app (or some other app that overwrites ReactActivityDelegate.createRootView method), on layout snapshot see custom root view being used. Differential Revision: D17482966 Pulled By: mdvacca fbshipit-source-id: 866f551b8b077bafe1eb9e34e5dccb1240fa935e
This commit will cause Blank screen for Android after just |
Summary
This change restores the possibility of injecting custom root views via ReactAcitivtyDelegate. It has been used by react-native-gesture-handler library in order to replace default root view with a one that'd route touch events to gesture-handler internal pipeline.
The regression happened in d0792d4 where new
ReactDelegate
was introduced to provide support for rendering react native views in both Android fragments and activities. As a part of that change the logic responsible for creating root view has been moved fromReactActivityDelegate
toReactDelegate
renderingReactActivityDelegate.createRootView
unused – that is there is no code path that leads to this method being called. InsteadReactDelegate.createRootView
method has been added which now plays the same role. The custom root view injection was relying on overwriting that method and hence the method is no longer referenced overwriting it has no effect. Following the logic migration out ofReactActivityDelegate
intoReactDelegate
we could potentially now start overwriting methods ofReactDelegate
. However when working with Android's activities in React Native we can only provide an instance ofReactActivityDelegate
and in my opinion it does not make too much sense to expose also a way to provide own instance ofReactDelegate
.The proposed fix was to route
ReactDelegate.createRootView
to callReactActivityDelegate.createRootView
and this way regaining control over root view creation toReactActivityDelgate
. The change of the behavior has been implemented by subclassingReactDelegate
directly fromReactActivityDelegate
and hooking the aforementioned methods together. Thanks to this approach, the change has no effect onReactDelegate
being used directly from fragments or in other scenarios where it is not being instantiated fromReactActivityDelegate
.This fixes an issue reported in software-mansion/react-native-gesture-handler#745 and discussed on 0.61 release thread: react-native-community/releases#140 (comment)
Changelog
[Internal] [Fixed] - Allow for custom root view to be injected via ReactActivityDelegate
Test Plan