Skip to content

fix(Android): adapt header insets when interface orientation changes #2756

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

Merged
merged 19 commits into from
Mar 13, 2025

Conversation

kkafar
Copy link
Member

@kkafar kkafar commented Mar 6, 2025

Description

We did not adapt header insets when interface orientation changes, leading to cases like on screenshots below 👇🏻

image

image

We want it to adapt to changing window insets properly.

What needs to be tested / answered:

  1. Pressables in header - insets change is not observed by ShadowTree -> this might lead to issues with pressables - checked on Test2466 in e2e and not e2e - seems to work ok
  2. String truncation - tested on TestHeaderTitle - seems to work ok (tested both e2e and not e2e & in any screen orientation)

This is how it works now (look only at header):

SDK 34 (no edge-to-edge) + no cutout

Screen.Recording.2025-03-07.at.14.39.14.mov

SDK 34 (no edge-to-edge) + cutout

Screen.Recording.2025-03-07.at.14.41.50.mov

SDK 35 (edge-to-edge) + no cutout

Screen.Recording.2025-03-07.at.14.45.21.mov

SDK 35 (edge-to-edge) + cutout

Screen.Recording.2025-03-07.at.14.46.16.mov

Let it be noted that I've also tested that it work's fine with button navigation.

Changes

I've moved all inset/padding related logic to CustomToolbar, because it is in different place in view hierarchy than HeaderConfig & the insets it receives are sometimes different & I wanted the logic manipulating CustomToolbar layout to live in CustomToolbar.

CustomToolbar now listens for dispatches of window insets & updates its horizontal paddings accordingly.

Currently I've decided that this behaviour will be controlled by isTopInsetEnabled prop on HeaderConfig together with the topInset.

Test code and steps to reproduce

  1. Use device with cutout / add cutout to emulator (in developer options)
  2. Run any example with header, e.g. TestFormSheet
  3. Change screen orientation & observe the header behaviour.

Checklist

  • Ensured that CI passes

@kkafar
Copy link
Member Author

kkafar commented Mar 7, 2025

There is stil issue when the app start s in landscape mode -> the header font is weirdly small, but this is not a regression and a separate problem. I'll tackle it in separate PR.

image

@kkafar kkafar requested a review from kligarski March 7, 2025 14:10
Copy link
Contributor

@kligarski kligarski left a comment

Choose a reason for hiding this comment

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

Looks good!

@kkafar kkafar merged commit 4cc47d9 into main Mar 13, 2025
3 of 4 checks passed
@kkafar kkafar deleted the @kkafar/horizontal-orientation-e2e branch March 13, 2025 20:23
kkafar added a commit that referenced this pull request May 7, 2025
…es (#2905)

## Description

Regression most likely introduced in 4.5.0 by #2466.
Fixes #2714
Fixes #2815
Supersedes #2845


This is a ugly hack to workaround issue with dynamic content change.
When the size of this shadow node contents (children) change due to JS
update, e.g. new icon is added, if the size is set for the yogaNode
corresponding to this shadow node, the enforced size will be used
and the size won't be updated by Yoga to reflect the contents size
change -> host tree won't get layout metrics update -> we won't trigger
native
layout -> the views in header will be positioned incorrectly.

> [!important]
> This PR handles iOS only, however there is **similar** issue on
Android. The issue can be reproduced on the same test example. Android
will be handled in separate PR.

## Changes

## Test code and steps to reproduce

In this approach I've settled with:

1. not calling set size on iOS for
`RNSScreenStackHeaderSubviewShadowNode`,
2. updating header config padding & sending it as state to shadow tree.

Added `Test2714`

Most of the fragile header interactions must be tested:

* [x] Header title truncation - `TestHeaderTitle` ~❌ This PR introduces
regression here on iOS (Android not tested yet)~ ✅ Works
* [x] Pressables in header - `Test2466` (iOS works, Android code is
unmodified here)
* [x] #2807
(this PR does not touch Android)
* [x] #2811
(this PR does not touch Android)
* [x] #2812
(this PR does not touch Android)
* [x] Header behaviour on orientation changes -
#2756 (this
PR does not touch Android)
* [x] New test `Test2714` handling header item resizing.
## Checklist

- [x] Included code example that can be used to test this change
- [ ] Ensured that CI passes
kkafar added a commit that referenced this pull request May 8, 2025
…hanges (#2910)

## Description

Fixes
#2714 on
Android
Fixes
#2815 on
Android

See #2905 for detailed description.

## Changes

Removed call to `RNSScreenStaceaderSubviewShadowNode.setSize` in
corresponding component descriptor.

It seems that we do not need to enforce node size from HostTree. Setting
appropriate content offset is enough for pressables to function
correctly (assuming that native layout **does not change size of any
subview**). I currently can't come up with any scenario where this would
happen.

## Test code and steps to reproduce

I've tested:

* [x] `Test2714` introduced in PR with iOS fixes -
#2905
* [x] Pressables in header -
#2466,
* [x] Header title truncation -
#2325 (only
few cases, as the list is long there) & noticed a regression (not
related to this PR, described in comment below the PR description),
* [x] Insets with orientation change (Android) -
#2756
* [x] #2807
(on `TestHeaderTitle` with call to `setOptions` in `useLayoutEffect`)
* [x] `Test2811` -
#2811
* [x] #2812
(with snippet provided in that PR description)



## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes
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.

2 participants