-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[Android] Redundant onLayout event #7202
Comments
fix #7250 |
I asked on Twitter and there's a module to detect screen rotation properly, you might want to use that instead: Your PR #7250 might still make sense though (let's wait for others to comment). |
@mkonicek It wasn't very usable on Android last time I tried it though - https://github.com/walmartreact/react-native-orientation-listener/issues |
I ran into this as well while evaluating different methods of detecting orientation change. There's various problems (at least for android) with the orientation-plugins out there. |
@mkconicek This issue causes problem on other cases than just orientation changes. For example, I've experience performance issues related to redundant layout events when animating a parent to a view that has on layout. In the app I'm working on I use onLayout to setState and this is causing the Android version to re-render component tree during animation and in turn causing animation to lag considerably. I've created a small reproducer to show the reduntant layout events when animating here: [https://rnplay.org/apps/DUpmUA]. The result is similar to @hayeah's example, I.E. animation does not trigger any layout event on iOS but on Android it triggers plenty of them. For me the PR #7250 fixes the issue and makes Android behave like iOS. (Merged it into 0.26-stable) |
Hi there! This issue is being closed because it has been inactive for a while. But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/android-redundant-onlayout-event Product Pains has been very useful in highlighting the top bugs and feature requests: Also, if this issue is a bug, please consider sending a pull request with a fix. |
I believe this issue is resolved and merged #7250 |
Summary: Fixes [facebook#7202 Android Redundant onLayout event](facebook#7202) Closes facebook#7250 Differential Revision: D4104066 Pulled By: mkonicek fbshipit-source-id: 383efdb4b4881aa7d7e508d61c9c01165bcf7bb6
Sample App: https://rnplay.org/apps/L_-nNQ
I am using a
RootView
component to detect device rotation, but when animating an absolutely positioned child View in the class hierarchy, the RootView is getting redundant layout events.On Android,
onDeviceRotation
gets a layout event for each frame (when the child view changes). On iOS,onDeviceRotation
is called only on initial layout.Digging into the source code, I found that:
The relevant code is below.
iOS Side
RCTUIManager dispatches onLayout event for views that received new frames.
See:
react-native/React/Modules/RCTUIManager.m
Lines 550 to 567 in 02578df
RCTShadowNodes checks if frame changed, it not, don't add the view to
viewsWithNewFrames
, thus preventing onLayout event to get dispatched.See:
react-native/React/Views/RCTShadowView.m
Lines 152 to 155 in 02578df
Android Side
Android always dispatch an event if the layout is dirtied. In our case, the child view dirties the parent. We can do something similar as iOS, by checking if the frame changed before dispatching an event.
See:
react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java
Lines 729 to 744 in 02578df
Specifically, we can change
dispatchUpdates
to return false if frame didn't change, and avoid dispatching the onLayout event.The text was updated successfully, but these errors were encountered: