Skip to content

fix(Android, Stack v5): set needsCustomLayoutForChildren to true for StackHost#4200

Open
kligarski wants to merge 1 commit into
@kligarski/stack-v5-android-refactorfrom
@kligarski/stack-v5-android-fix-orientation
Open

fix(Android, Stack v5): set needsCustomLayoutForChildren to true for StackHost#4200
kligarski wants to merge 1 commit into
@kligarski/stack-v5-android-refactorfrom
@kligarski/stack-v5-android-fix-orientation

Conversation

@kligarski

@kligarski kligarski commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

Disables layout from Yoga for children of StackHost. Fixes a nondeterministic bug with incorrect screen size on orientation change.

Closes https://github.com/software-mansion/react-native-screens-labs/issues/1499.

Details

On orientation change, sometimes measure & layout from Yoga was applied with incorrect measurements. This is very likely connected to https://github.com/software-mansion/react-native-screens-labs/discussions/543, #3295 but I didn't investigate further why we receive the outdated measurements.

In order to mitigate this, I decided to use similar strategy to StackHeaderConfig. By enabling needsCustomLayoutForChildren in StackHostViewManager, we will still receive measure with incorrect width & height from Yoga but layout won't be called. This way, incorrect measurements won't be applied and next native layout will remeasure & apply correct layout. Ultimately, we want the screen to be laid out fully by native layout, not by Yoga, so this is the desired behavior. If anything changes, StackHost receives new measurement from Yoga and will trigger native layout pass for StackScreen.

Changes

  • set needsCustomLayoutForChildren=true in StackHostViewManager

Before & after - visual documentation

Before After
before_orientation.mp4
after_orientation.mp4

Test plan

Run test-stack-toolbar-menu-show-as-action. Change orientation portrait -> landscape -> portrait multiple times. The content of the screen should be laid out correctly.

Checklist

  • Included code example that can be used to test this change.
  • For visual changes, included screenshots / GIFs / recordings documenting the change.
  • Ensured that CI passes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR mitigates a nondeterministic Android orientation-change sizing issue in Stack v5 by preventing Yoga from directly laying out StackHost children, ensuring child positioning is driven by native layout.

Changes:

  • Override needsCustomLayoutForChildren() in StackHostViewManager to return true.
  • Add rationale in KDoc explaining why Yoga layout for children should be bypassed for StackHost.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kkafar kkafar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes perfect sense to me.

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.

4 participants