Repository navigation
Keep the host navigation bar for transparent Modals on Android - #60204
Open
fairysword wants to merge 1 commit into
Open
fairysword wants to merge 1 commit into
fairysword wants to merge 1 commit into
Conversation
Summary: A transparent `Modal` with a translucent navigation bar changes the host app's navigation bar when the app's style differs from the system theme, for example a dark app with a black navigation bar and light buttons while the system is in light mode. `ReactModalHostView` calls `enableEdgeToEdge()` on the dialog window, which derives the navigation bar from the system UI mode: - Below Android 10 it emulates navigation bar contrast with a scrim in `navigationBarColor`. react#58491 disabled the contrast scrim for transparent modals through `isNavigationBarContrastEnforced`, which doesn't exist below Android 10, so the navigation bar turns white. - On all versions it requests dark navigation buttons in light mode. The dialog is the top full-screen window, so the system draws the buttons in its style over the host's navigation bar. `updateSystemAppearance()` only runs once after `show()`, and doesn't sync the navigation button style on Android 12+. For transparent modals, this sets `navigationBarColor` to transparent below Android 10 and syncs the dialog's navigation button style from the host window after every `enableEdgeToEdge()` call. Up to Android 11 the host style is read from `systemUiVisibility`, because on Android 11 the `WindowInsetsControllerCompat` getter marks the host window's appearance as app-controlled, which makes later `systemUiVisibility` light flags, such as those set by `StatusBar`, ineffective. Opaque modals keep the current scrim behavior. Changelog: [Android][Fixed] - Keep the host navigation bar color and button style for transparent Modals Test Plan: - `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.modal.ReactModalHostViewNavigationBarTest'`: 7 cases pass, 6 fail without this change. - `yarn format-check-kotlin` - Manually verified with a transparent bottom sheet Modal in RNTester on Android 9 and Android 16, 3-button navigation, light mode.
Visual regressionNo visual differences at ios: no capture |
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:
A transparent
Modalchanges the host app's navigation bar when the app's navigation bar style differs from the system theme, for example a dark app with a black navigation bar and light buttons while the system is in light mode. Opening a transparent bottom sheet then turns the navigation bar white below Android 10, and switches the navigation buttons to the dark style on Android 10+. The reverse combination is affected too: for a light app with a white navigation bar and dark buttons while the system is in dark mode, the buttons switch to the light style on Android 10+ and become invisible over light content.ReactModalHostViewcallsenableEdgeToEdge()on the dialog window. That function derives the navigation bar from the system UI mode, not from the host window:enableEdgeToEdge()emulates navigation bar contrast by setting the window'snavigationBarColorto a scrim (90% white in light mode). Fix Android navigation bar transparency for Modal (#58491) #58491 disabled the contrast scrim for transparent modals on Android 10+ throughisNavigationBarContrastEnforced, but that API does not exist below Android 10, so the scrim stays and the navigation bar turns white.enableEdgeToEdge()sets the navigation button style from the system theme. In light mode the dialog window requestsAPPEARANCE_LIGHT_NAVIGATION_BARS(dark buttons), and in dark mode it clears it (light buttons). The dialog is a full-screen application window above the activity, soDisplayPolicypicks it as the navigation bar color window and draws the buttons in its style over the host's navigation bar.updateSystemAppearance()doesn't prevent this:systemUiVisibilityonce aftershow().updateProperties()runs again on later prop updates and ononHostResume, and callsenableEdgeToEdge(), which resets the style. On Android 11 the copy has no effect at all, because theWindowInsetsControllercall inenableEdgeToEdge()marks the dialog's appearance as app-controlled, sosystemUiVisibilitylight flags are ignored.For transparent modals with a translucent navigation bar, this PR:
navigationBarColorto transparent below Android 10, matching what Fix Android navigation bar transparency for Modal (#58491) #58491 does on Android 10+;enableEdgeToEdge()call. Up to Android 11, the host style is read fromsystemUiVisibilityrather thanWindowInsetsControllerCompat, because on Android 11 the compat getter would mark the host window's appearance as app-controlled and break latersystemUiVisibilityupdates on the host, such asStatusBar.setBarStyle.Opaque modals keep the current scrim behavior.
Changelog:
[ANDROID] [FIXED] - Keep the host navigation bar color and button style for transparent Modals
Test Plan:
Unit tests
ReactModalHostViewNavigationBarTestruns 7 cases. The scrim cases run on SDK 28; the button style case runs on SDK 28, 29 and 33, covering both thesystemUiVisibilitypath and theWindowInsetsControllerpath. All pass with this change; 6 fail without it. The remaining case guards the existing scrim behavior of opaque modals.Manual repro
Repro branch: repro/modal-navigation-bar (RNTester changes only, not part of this PR):
RNTesterActivitydraws a black navigation bar with light buttons after React Native's edge-to-edge setup.Modal(transparent+statusBarTranslucent).Steps:
Appearance.setColorScheme('dark'), makes the Modal derive a dark scrim and hides the bug. The reverse combination, a light app in dark mode, is shown at the end.Expected: the navigation bar stays black with light buttons.
Android 9 (API 28), 3-button navigation, light mode. Before the fix, the navigation bar turns into a white scrim with dark buttons:
Android 16 (API 36) emulator with a Google APIs image, 3-button navigation, light mode. The background stays dark (#58491), but before the fix the dialog window requests dark buttons (
dumpsys window:apr=LIGHT_NAVIGATION_BARS) and the Taskbar draws them at full dark intensity (mTaskbarNavButtonDarkIntensity=1.0), so the buttons turn from white to gray. After the fix, the dialog window has no navigation appearance flag and the buttons stay white, the same as a plain nativeDialogover this activity:The reverse combination on the same emulator in dark mode, with RNTester locally switched to a light app that draws a white navigation bar with dark buttons. Before the fix, the dialog window clears
LIGHT_NAVIGATION_BARSand the Taskbar draws light buttons (mTaskbarNavButtonDarkIntensity=0.0), so the buttons disappear over the white bottom sheet. After the fix, the dialog window requests dark buttons like the host (mTaskbarNavButtonDarkIntensity=1.0):Not tested on Android 10 and 11 devices. Android 10 uses the same
systemUiVisibilitypath as Android 9 and is covered by the SDK 29 unit test.