Repository navigation
Fix Android Modal initial bounds for translucent system bars - #60258
Open
fairysword wants to merge 1 commit into
Open
fairysword wants to merge 1 commit into
fairysword wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
On Android with Fabric, the initial size of a Modal's content comes from
ModalHostViewComponentDescriptor::createInitialState, which callsFabricUIManager.getEncodedScreenSizeWithoutVerticalInsets. That method always subtracts both the top and bottom system bar insets, regardless ofstatusBarTranslucent,navigationBarTranslucentor the app-wide edge-to-edge setting. When the Dialog's content actually extends under one or both bars, the firstonSizeChangedcorrects the size, so bottom-aligned content such as a bottom sheet visibly jumps when the Modal opens.This change passes the two existing props through JNI and subtracts only the insets that the Dialog content is laid out within:
statusBarTranslucentnavigationBarTranslucentfalsefalsetruefalsetruetruefalsetrue(unsupported combination)The mapping lives in
ModalContentInsets.kt, next toReactModalHostView, and mirrors its window configuration: with an opaque status bar the contentFrameLayoutfits the system windows, and only a Modal with both bars translucent extends under the bottom inset.The width calculation, the inset types, the cached screen metrics, the subsequent
onSizeChangedupdates and the Dialog appearance are unchanged.Depends on #60257
On API 30 and below,
updateSystemAppearance()copies the Activity'ssystemUiVisibilityover the Dialog's and drops the Dialog's own edge-to-edge layout flags until the nextshowOrUpdate()re-applies them. With both bars translucent, this PR alone makes the initial size correct but exposes that transient drop: the root goes780 → 704 → 780 dpinstead of704 → 780 dp. #60257 fixes the flags and should land first. With both changes, the root stays at 780 dp.Changelog:
[ANDROID] [FIXED] - Fix Modal content jumping after its first layout when
statusBarTranslucent,navigationBarTranslucentor edge-to-edge is enabledTest Plan:
Unit tests
ModalContentInsetsTestcovers all eight combinations of the edge-to-edge setting and the two props.DisplayMetricsHolderTestcovers subtracting both insets, only the bottom inset, and neither.Reproduction
A transparent Modal with a bottom-aligned sheet, logging the root and sheet
onLayoutheights:Before this change, whenever either bar is translucent or edge-to-edge is enabled, the first
rootevent reports the height without both bars and a second event corrects it. After it, the first event already reports the final height.Physical devices
Root heights in dp.
a → bmeans the first layout wasaand was corrected tobafter the Dialog was measured.On the vivo device, nine fresh mounts with the original 300 ms entrance animation also reported the final root and sheet heights on the first layout, with no later correction.
Videos
One video per row of the table above, in the same order. Left: before. Right: after. Both builds use the same device and static content. The entrance animation is disabled identically in both builds so that only the bounds correction is visible. Clips are aligned to the first frame of the backdrop and slowed uniformly to 0.1× without interpolation.
Venus e5, API 28
Both bars opaque (control): no change expected.
api28-venus-both-bars-opaque.mp4
Only the status bar translucent
api28-venus-status-bar-translucent.mp4
Both bars translucent: without #60257, so the after side still shows the transient drop.
api28-venus-both-bars-translucent.mp4
Samsung S24, API 34
Both bars opaque (control): no change expected.
api34-samsung-both-bars-opaque.mp4
Only the status bar translucent
api34-samsung-status-bar-translucent.mp4
Both bars translucent
api34-samsung-both-bars-translucent.mp4
vivo V2338A, API 36, gesture navigation
System-enforced edge-to-edge
api36-vivo-system-edge-to-edge.mp4