Skip to content

Fix Android Modal initial bounds for translucent system bars - #60258

Open
fairysword wants to merge 1 commit into
react:mainfrom
fairysword:fix/modal-initial-layout
Open

fairysword wants to merge 1 commit into
react:mainfrom
fairysword:fix/modal-initial-layout

Conversation

@fairysword

Copy link
Copy Markdown
Contributor

Summary:

On Android with Fabric, the initial size of a Modal's content comes from ModalHostViewComponentDescriptor::createInitialState, which calls FabricUIManager.getEncodedScreenSizeWithoutVerticalInsets. That method always subtracts both the top and bottom system bar insets, regardless of statusBarTranslucent, navigationBarTranslucent or the app-wide edge-to-edge setting. When the Dialog's content actually extends under one or both bars, the first onSizeChanged corrects 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:

Edge-to-edge enabled statusBarTranslucent navigationBarTranslucent Subtracted insets
Yes any any none
No false false top and bottom
No true false bottom
No true true none
No false true (unsupported combination) top and bottom

The mapping lives in ModalContentInsets.kt, next to ReactModalHostView, and mirrors its window configuration: with an opaque status bar the content FrameLayout fits 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 onSizeChanged updates and the Dialog appearance are unchanged.

Depends on #60257

On API 30 and below, updateSystemAppearance() copies the Activity's systemUiVisibility over the Dialog's and drops the Dialog's own edge-to-edge layout flags until the next showOrUpdate() re-applies them. With both bars translucent, this PR alone makes the initial size correct but exposes that transient drop: the root goes 780 → 704 → 780 dp instead of 704 → 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, navigationBarTranslucent or edge-to-edge is enabled

Test Plan:

Unit tests

./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest \
  --tests com.facebook.react.views.modal.ModalContentInsetsTest \
  --tests com.facebook.react.uimanager.DisplayMetricsHolderTest

ModalContentInsetsTest covers all eight combinations of the edge-to-edge setting and the two props. DisplayMetricsHolderTest covers subtracting both insets, only the bottom inset, and neither.

Reproduction

A transparent Modal with a bottom-aligned sheet, logging the root and sheet onLayout heights:

<Modal transparent animationType="none" statusBarTranslucent navigationBarTranslucent>
  <View
    style={{flex: 1, justifyContent: 'flex-end', backgroundColor: 'rgba(0, 0, 0, 0.5)'}}
    onLayout={e => console.log('root', e.nativeEvent.layout.height)}>
    <View
      style={{maxHeight: '60%', backgroundColor: 'white'}}
      onLayout={e => console.log('sheet', e.nativeEvent.layout.height)}>
      {/* content */}
    </View>
  </View>
</Modal>

Before this change, whenever either bar is translucent or edge-to-edge is enabled, the first root event 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 → b means the first layout was a and was corrected to b after the Dialog was measured.

Device Configuration Before After
Venus e5, API 28 Both bars opaque (control) 704 704
Venus e5, API 28 Only the status bar translucent 704 → 732 732
Venus e5, API 28 Both bars translucent 704 → 780 780 → 704 → 780 (see "Depends on" above)
Samsung S24, API 34 Both bars opaque (control) 785.78 785.78
Samsung S24, API 34 Only the status bar translucent 785.78 → 817.07 817.07
Samsung S24, API 34 Both bars translucent 785.78 → 832 832
vivo V2338A, API 36, gesture navigation System-enforced edge-to-edge 742 → 800 800

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 24, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant