Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ protected void handleOnDestroy() {
cameraXView = null;
}
lastSessionConfig = null;
restoreSystemUiForToBackMode(getBridge().getActivity());
}

private CameraSessionConfiguration lastSessionConfig;
Expand Down Expand Up @@ -136,6 +137,9 @@ protected void handleOnDestroy() {
private Drawable originalWindowBackground;
private Float originalWebViewAlpha;
private Drawable originalWebViewParentBackground;
private Integer originalStatusBarColor;
private Integer originalNavigationBarColor;
private Boolean originalNavigationBarContrastEnforced;
private boolean isCameraPermissionDialogShowing = false;

@PluginMethod
Expand Down Expand Up @@ -433,6 +437,7 @@ public void stop(final PluginCall call) {
originalWindowBackground = null;
}
restoreWebViewVisualState();
restoreSystemUiForToBackMode(getBridge().getActivity());
call.resolve();
});
}
Expand Down Expand Up @@ -947,6 +952,7 @@ private void startCamera(final PluginCall call) {
getBridge()
.getActivity()
.runOnUiThread(() -> {
lockSystemUiForToBackMode(getBridge().getActivity(), toBack);
// Ensure transparent background when preview is behind the WebView (Android 10 fix)
if (toBack) {
try {
Expand Down Expand Up @@ -1531,6 +1537,70 @@ private boolean isMiuiDevice() {
return manufacturer.contains("xiaomi") || brand.contains("xiaomi") || brand.contains("redmi") || brand.contains("poco");
}

private int toOpaqueColor(int color) {
return Color.argb(255, Color.red(color), Color.green(color), Color.blue(color));
}

private void lockSystemUiForToBackMode(Activity activity, boolean toBack) {
if (activity == null) {
return;
}
if (!toBack) {
return;
}
Comment on lines +1548 to +1550
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore system UI before returning on non-toBack start

This early return skips cleanup when a previous session already locked system bars for toBack=true. In a valid flow like start({ force: true, toBack: false }), the old session is stopped without calling stop(), so originalStatusBarColor/originalNavigationBarColor remain cached and the status/navigation bars stay forced to opaque colors (and contrast disabled on Android Q+) even though the new session is not toBack; this leaves the app UI in an incorrect state until a later explicit restore path runs.

Useful? React with πŸ‘Β / πŸ‘Ž.


try {
if (originalStatusBarColor == null) {
originalStatusBarColor = activity.getWindow().getStatusBarColor();
}
if (originalNavigationBarColor == null) {
originalNavigationBarColor = activity.getWindow().getNavigationBarColor();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && originalNavigationBarContrastEnforced == null) {
originalNavigationBarContrastEnforced = activity.getWindow().isNavigationBarContrastEnforced();
}

int statusBarColor = toOpaqueColor(originalStatusBarColor != null ? originalStatusBarColor : Color.BLACK);
int navigationBarColor = toOpaqueColor(originalNavigationBarColor != null ? originalNavigationBarColor : Color.BLACK);

activity.getWindow().setStatusBarColor(statusBarColor);
activity.getWindow().setNavigationBarColor(navigationBarColor);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
activity.getWindow().setNavigationBarContrastEnforced(false);
}
} catch (Exception e) {
Log.w(TAG, "Failed to lock system UI colors for toBack mode", e);
}
}

private void restoreSystemUiForToBackMode(Activity activity) {
final Integer statusBarColor = originalStatusBarColor;
final Integer navigationBarColor = originalNavigationBarColor;
final Boolean navigationBarContrastEnforced = originalNavigationBarContrastEnforced;
originalStatusBarColor = null;
originalNavigationBarColor = null;
originalNavigationBarContrastEnforced = null;

if (activity == null) {
return;
}

activity.runOnUiThread(() -> {
try {
if (statusBarColor != null) {
activity.getWindow().setStatusBarColor(statusBarColor);
}
if (navigationBarColor != null) {
activity.getWindow().setNavigationBarColor(navigationBarColor);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && navigationBarContrastEnforced != null) {
activity.getWindow().setNavigationBarContrastEnforced(navigationBarContrastEnforced);
}
} catch (Exception ignored) {}
});
}

private void applyTransparentBackgroundsForToBack() {
if (!isToBackMode()) {
return;
Expand Down Expand Up @@ -1801,6 +1871,7 @@ public void onCameraStartError(String message) {
}
}
restoreWebViewVisualState();
restoreSystemUiForToBackMode(getBridge().getActivity());
}

@PluginMethod
Expand Down