Repository navigation
Match the status bar icons of the Android modal to the screen behind it - #194
Merged
Merged
Conversation
The modal opens a Compose Dialog, which has its own window. Nothing set the status bar appearance on that window, so its icons stayed white and were almost invisible on a light background. Copy the appearance from the activity's window, which applies status_bar_style.
Member
|
thanks! |
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.
On Android, the status bar icons in a
native:modalare always white. In the light theme the modal has a light background, so the clock and the icons are almost invisible. When the modal closes, the screen shows its dark icons again.We found it in our app: a photo viewer in a modal with
:dismissible="false", in the light theme.Steps to reproduce
Set the device to the light theme, open the screen on Android and tap Open.
status_bar_styleinconfig/nativephp.phphas no effect on the modal either. Withdark, the screen has dark icons and the modal has white icons.Cause
ModalRenderer.ktopens a ComposeDialogwithdecorFitsSystemWindows = false. The dialog has its own window, and that window draws behind the status bar.MainActivity.configureStatusBar()sets the status bar appearance only on the activity's window. Nothing sets it on the dialog's window, so that window keeps the default, which is white icons.adb shell dumpsys window windowsshows this while the modal is open. The activity's window hasapr=LIGHT_STATUS_BARS LIGHT_NAVIGATION_BARS. The dialog's window has noaprline.The dark theme hides the problem, because white icons are correct there.
Changes
SideEffectin theDialogcontent readsisAppearanceLightStatusBarsfrom the activity's window and sets it on the dialog's window. The renderer gets the activity fromMainActivity.instance, asWebviewRenderer.ktdoes.isSystemInDarkTheme(), because the activity appliesstatus_bar_styleand that value is private toMainActivity. Soauto,lightanddarkall hold in the modal, and the modal always matches the screen behind it.SideEffectruns again when the theme changes, so an open modal follows the change.tests/ModalRendererTest.phpgets one test that checks this in the Kotlin source. It fails on the old code.native:bottom-sheetalso has its own window. Its icons were already dark in the light theme, so this change does not touch it.How I tested
Android 16 emulator (API 36.1), in an app on nativephp/mobile 4.7.0, nativephp/mobile-ui 0.9.0 and Compose UI 1.10.0, with
ModalRenderer.ktfrom 0.9.0 (before) and from this branch (after).There were two test screens: the component above, and a modal with
:dismissible="false"and its own close button.autoran on both screens,darkandlighton the second one. I took a screenshot of each state and read the color of the clock digits from it.status_bar_styleautoautodarkdarklightlightadb shell cmd uimode night): the icons follow the theme on both test screens. After the modal closes, the screen has the right icons.Not tested: a physical device, Android 13 to 15, and a modal inside a bottom sheet. iOS does not change.
Before Android 15, the system does not force a transparent status bar. I read the code for this case but did not run it. The app theme
Theme.AndroidPHPsetsandroid:statusBarColorto transparent, in the light and in the dark variant, and the dialog overlay does not set a color. So the modal's background should still be behind the icons. I read this in the API 36 sources.Also seen, the same before and after this change: in the dark theme, the plain
<native:text>in the modal above is dark on the dark background. I did not look into it, and I did not change it here.