From 8afa0378cd09b8fa6c30d759539fc9a680e8cae2 Mon Sep 17 00:00:00 2001 From: rogerkerse Date: Tue, 29 Jan 2019 07:09:52 -0800 Subject: [PATCH] SystemUiVisibility overwritten bug (#17370) Summary: Make StatusBar style respect previously set systemUiVisibility I tried to set `SystemUiVisibility` flag to `SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR` to enable Android's light soft navigation bar, but when I had `` component in my view, then it was always overwritten. This is how I found the bug and fixed it. 1. In MainActivity you can set systemUiFlags like this in onCreate method ``` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Window window = getWindow(); View rootView = window.getDecorView().getRootView(); rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); } ``` 2. Add to a view 3. In `android/app/build.gradle` file set `targetSdkVersion` to **27** instead of 22 or something like that 4. In `android/app/src/main/res/values/styles.xml` add 2 lines to `AppTheme` ``` true #ffffff ``` 5. Run the app. 6. Test. Previously bottom soft navigation bar was set to white and buttons also to white (so they weren't visible anymore), because StatusBar was overwriting previously set systemUiVisibility Flags. Now the bar should be white and buttons dark as expected. Previous buggy android bottom navbar screen shot 2017-12-27 at 17 11 57 New fixed android bottom navbar screen shot 2017-12-27 at 17 12 07 This pull request does not change any existing feature. It only makes StatusBar coloring work more properly without affecting bottom navigation bar on android or any other system ui visibility feature. [ANDROID] [BUGFIX] [StatusBar] - Fixed StatusBar overwriting previously set SystemUiVisibility flags Pull Request resolved: https://github.com/facebook/react-native/pull/17370 Differential Revision: D13860079 Pulled By: cpojer fbshipit-source-id: a0bca7acb7601eb78f0842239ea4dee76a63d1fd --- .../react/modules/statusbar/StatusBarModule.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java index e21912b51..3c0da261d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java @@ -189,8 +189,13 @@ public class StatusBarModule extends ReactContextBaseJavaModule { @Override public void run() { View decorView = activity.getWindow().getDecorView(); - decorView.setSystemUiVisibility( - "dark-content".equals(style) ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0); + int systemUiVisibilityFlags = decorView.getSystemUiVisibility(); + if ("dark-content".equals(style)) { + systemUiVisibilityFlags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + } else { + systemUiVisibilityFlags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + } + decorView.setSystemUiVisibility(systemUiVisibilityFlags); } } );