Skip to content

Commit

Permalink
Apply translucent flag only if needed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
guyca committed Dec 26, 2019
1 parent 1f611c6 commit 6782362
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void setTranslucent(StatusBarOptions options) {
Window window = activity.getWindow();
if (options.translucent.isTrue()) {
window.setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
} else {
} else if (StatusBarUtils.isTranslucent(window)) {
window.clearFlags(FLAG_TRANSLUCENT_STATUS);
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ private void setTextColorScheme(TextColorScheme scheme) {
}
}

private static void clearDarkTextColorScheme(View view) {
private void clearDarkTextColorScheme(View view) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
int flags = view.getSystemUiVisibility();
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
Expand Down Expand Up @@ -168,7 +168,7 @@ private void mergeTranslucent(StatusBarOptions options) {
Window window = activity.getWindow();
if (options.translucent.isTrue()) {
window.setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
} else if (options.translucent.isFalse()) {
} else if (options.translucent.isFalse() && StatusBarUtils.isTranslucent(window)) {
window.clearFlags(FLAG_TRANSLUCENT_STATUS);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.view.Window;
import android.view.WindowManager;

import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
import static com.reactnativenavigation.utils.UiUtils.dpToPx;

public class StatusBarUtils {
Expand All @@ -27,4 +30,8 @@ public static int getStatusBarHeight(Context context) {
return statusBarHeight;
}

public static boolean isTranslucent(Window window) {
WindowManager.LayoutParams lp = window.getAttributes();
return (lp.flags & FLAG_TRANSLUCENT_STATUS) == FLAG_TRANSLUCENT_STATUS;
}
}

0 comments on commit 6782362

Please sign in to comment.