Browse Source

Apply translucent flag only if needed

This works around a rare edge case where applying the translucent flag
resulted in white screens when pushing or showing modals.
So far, I've managed to reproduce this only when when showing external component as modal in the Wix app.

closes #5742
Guy Carmeli 5 years ago
parent
commit
6782362035

+ 3
- 3
lib/android/app/src/main/java/com/reactnativenavigation/presentation/Presenter.java View File

97
         Window window = activity.getWindow();
97
         Window window = activity.getWindow();
98
         if (options.translucent.isTrue()) {
98
         if (options.translucent.isTrue()) {
99
             window.setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
99
             window.setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
100
-        } else {
100
+        } else if (StatusBarUtils.isTranslucent(window)) {
101
             window.clearFlags(FLAG_TRANSLUCENT_STATUS);
101
             window.clearFlags(FLAG_TRANSLUCENT_STATUS);
102
         }
102
         }
103
     }
103
     }
132
         }
132
         }
133
     }
133
     }
134
 
134
 
135
-    private static void clearDarkTextColorScheme(View view) {
135
+    private void clearDarkTextColorScheme(View view) {
136
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
136
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
137
         int flags = view.getSystemUiVisibility();
137
         int flags = view.getSystemUiVisibility();
138
         flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
138
         flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
168
         Window window = activity.getWindow();
168
         Window window = activity.getWindow();
169
         if (options.translucent.isTrue()) {
169
         if (options.translucent.isTrue()) {
170
             window.setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
170
             window.setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
171
-        } else if (options.translucent.isFalse()) {
171
+        } else if (options.translucent.isFalse() && StatusBarUtils.isTranslucent(window)) {
172
             window.clearFlags(FLAG_TRANSLUCENT_STATUS);
172
             window.clearFlags(FLAG_TRANSLUCENT_STATUS);
173
         }
173
         }
174
     }
174
     }

+ 7
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.java View File

3
 import android.content.Context;
3
 import android.content.Context;
4
 import android.content.res.Resources;
4
 import android.content.res.Resources;
5
 import android.os.Build;
5
 import android.os.Build;
6
+import android.view.Window;
7
+import android.view.WindowManager;
6
 
8
 
9
+import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
7
 import static com.reactnativenavigation.utils.UiUtils.dpToPx;
10
 import static com.reactnativenavigation.utils.UiUtils.dpToPx;
8
 
11
 
9
 public class StatusBarUtils {
12
 public class StatusBarUtils {
27
         return statusBarHeight;
30
         return statusBarHeight;
28
     }
31
     }
29
 
32
 
33
+    public static boolean isTranslucent(Window window) {
34
+        WindowManager.LayoutParams lp = window.getAttributes();
35
+        return (lp.flags & FLAG_TRANSLUCENT_STATUS) == FLAG_TRANSLUCENT_STATUS;
36
+    }
30
 }
37
 }