Skip to content

[android] layout shift bug on new architecture #2933

@AndreiCalazans

Description

@AndreiCalazans

Description

When changing orientation we see large layout shifts occurring in the new
archicture. Upon close investigation we isolated the problem to be related to
react-native-screen's Screen component.

isolated-reproduction-orientation-issue.mp4

Note, while in this reproducible this is fast. In a large app with busy threads
the layout shift is way more prominent giving users a broken App sensation.

Also note how the padding applied to Screen is showing but then disappears?

At first we thought this was particularly related to absolute layout positioning
but further investigation proved us wrong.

We found that this onLayout updateState call in FabricEnabledViewGroup onLayout triggered by the ScreenContainer's onLayout causes a layout change that is different from the layout represented in the Shadow Tree. In consequence it causes a large layout shift when orientation change happens and overrides the underlying padding.

We don't understand yet why this updateState exists but removing it does seem to
fix things, see video below:

without-onLayout-new-arch.mp4

Now I'm not sure how to proceed here, I'd like to understand the following:

  1. Why does this updateState exist?
  2. if we need to keep it how do we ensure possibly schedule the update to occur
    together with its children layout to avoid the layout shift?
  3. is this maybe just a problem of incorrect dimenisions here?
  4. does Fabric now make this code unnecessary given I didn't find any bugs in
    our App by testing it without this logic?

Note that I used React Native 0.78.2 and RN Screens 3.37.0 because it's what we have in our app but the code is exactly the same in the latest version which I assume means the same behavior exists.

Steps to reproduce

  1. Run the reproducible locally
  2. Change orientation back and forth notice the blue background flash.

Snack or a link to a repository

https://github.com/AndreiCalazans/reproducible-rn-screens-absolute-layout-shift-new-arch/tree/main

Screens version

3.37.0

React Native version

0.78.2

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

Real device

Device model

Samsung A22

Acknowledgements

Yes

Metadata

Metadata

Assignees

Labels

Platform: AndroidThis issue is specific to AndroidRepro providedA reproduction with a snack or repo is provided

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions