fix(iOS, Paper): fix header layout when updating non focued screen #2552
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Note
This issue seems to concern only old architecture. See below for description of Fabric situation 👇🏻
This PR aims to fix a bug described below 👇🏻 and at the same time balancing on the thin edge of not introducing regressions regarding: #2316, #2248, #2385.
Bug description
See
Test2552
.The flow is as follows:
useLayoutEffect
we schedule a timer which callback changing the subview elements,Screen.Recording.2024-12-06.at.17.15.13.mov
Basically what happens is we're sending
layoutIfNeeded
to navigation bar before subviews are mounted under navigation bar view hierarchy. This causes "isLayoutDirty" flags to be cleaned up and subsequentlayoutIfNeeded
messages have no effect.Changes
We now wait with triggering layout for the subview to be attached to window.
Note
TODO: possibly we should call the layout from
didMoveToWindow
but I haven't found the case it does not work without the call, so I'm not adding it for now.Note
Calling layout on whole navigation bar for every subview update seems wrong, however the change is subview change can have effect on other neighbouring views (e.g. long title which need to be truncated) & it seems that we need to do this. Maybe we could get away will requesting it only from UINavigationBarContentView skipping few levels, but this is left for consideration in the future.
Important
I do not understand why we need to send
layoutIfNeeded
andsetNeedsLayout
is not enough, but not sending the former results in regressions in Test432. Leaving it for future considerations.Fabric
The strategy with setting screen options inside timer nested in useLayoutEffect seems to not work at all on new architecture. My impression is that the timer gets cancelled every time the screen loses focus (tab is changed). I do not know whether this is a bug on our side, or maybe it should work this way or it is Fabric bug. This should be debugged in future.
Test code and steps to reproduce
Test2552 - Follows the steps described above ☝🏻
Test432 - Follow the steps from issues described in mentioned issues ☝️
Checklist