Breaking: Ignore StatusBarManager rejected state
Summary: See #10236 Closes https://github.com/facebook/react-native/pull/10421 Differential Revision: D4045455 fbshipit-source-id: a4fd969b1ade5e1a44715c6aeebb12b58bbf8d0c
This commit is contained in:
parent
3683beb88a
commit
b67c0c964e
|
@ -7,6 +7,7 @@ android_library(
|
||||||
react_native_dep('third-party/android/support/v4:lib-support-v4'),
|
react_native_dep('third-party/android/support/v4:lib-support-v4'),
|
||||||
react_native_dep('third-party/java/infer-annotations:infer-annotations'),
|
react_native_dep('third-party/java/infer-annotations:infer-annotations'),
|
||||||
react_native_dep('third-party/java/jsr-305:jsr-305'),
|
react_native_dep('third-party/java/jsr-305:jsr-305'),
|
||||||
|
react_native_dep('libraries/fbcore/src/main/java/com/facebook/common/logging:logging'),
|
||||||
react_native_target('java/com/facebook/react/bridge:bridge'),
|
react_native_target('java/com/facebook/react/bridge:bridge'),
|
||||||
react_native_target('java/com/facebook/react/common:common'),
|
react_native_target('java/com/facebook/react/common:common'),
|
||||||
react_native_target('java/com/facebook/react/module/annotations:annotations'),
|
react_native_target('java/com/facebook/react/module/annotations:annotations'),
|
||||||
|
|
|
@ -20,29 +20,27 @@ import android.view.View;
|
||||||
import android.view.WindowInsets;
|
import android.view.WindowInsets;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import java.util.Map;
|
import com.facebook.common.logging.FLog;
|
||||||
|
import com.facebook.react.bridge.NativeModule;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.facebook.react.bridge.Promise;
|
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
import com.facebook.react.bridge.UiThreadUtil;
|
import com.facebook.react.bridge.UiThreadUtil;
|
||||||
import com.facebook.react.common.MapBuilder;
|
import com.facebook.react.common.MapBuilder;
|
||||||
|
import com.facebook.react.common.ReactConstants;
|
||||||
import com.facebook.react.module.annotations.ReactModule;
|
import com.facebook.react.module.annotations.ReactModule;
|
||||||
import com.facebook.react.uimanager.PixelUtil;
|
import com.facebook.react.uimanager.PixelUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link NativeModule} that allows changing the appearance of the status bar.
|
* {@link NativeModule} that allows changing the appearance of the status bar.
|
||||||
*/
|
*/
|
||||||
@ReactModule(name = "StatusBarManager")
|
@ReactModule(name = "StatusBarManager")
|
||||||
public class StatusBarModule extends ReactContextBaseJavaModule {
|
public class StatusBarModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
private static final String ERROR_NO_ACTIVITY = "E_NO_ACTIVITY";
|
|
||||||
private static final String ERROR_NO_ACTIVITY_MESSAGE =
|
|
||||||
"Tried to change the status bar while not attached to an Activity";
|
|
||||||
|
|
||||||
private static final String HEIGHT_KEY = "HEIGHT";
|
private static final String HEIGHT_KEY = "HEIGHT";
|
||||||
|
|
||||||
public StatusBarModule(ReactApplicationContext reactContext) {
|
public StatusBarModule(ReactApplicationContext reactContext) {
|
||||||
|
@ -68,10 +66,10 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void setColor(final int color, final boolean animated, final Promise res) {
|
public void setColor(final int color, final boolean animated) {
|
||||||
final Activity activity = getCurrentActivity();
|
final Activity activity = getCurrentActivity();
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
|
FLog.w(ReactConstants.TAG, "StatusBarModule: Ignored status bar change, current activity is null.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,19 +97,16 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
|
||||||
} else {
|
} else {
|
||||||
activity.getWindow().setStatusBarColor(color);
|
activity.getWindow().setStatusBarColor(color);
|
||||||
}
|
}
|
||||||
res.resolve(null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
res.resolve(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void setTranslucent(final boolean translucent, final Promise res) {
|
public void setTranslucent(final boolean translucent) {
|
||||||
final Activity activity = getCurrentActivity();
|
final Activity activity = getCurrentActivity();
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
|
FLog.w(ReactConstants.TAG, "StatusBarModule: Ignored status bar change, current activity is null.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,17 +136,16 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewCompat.requestApplyInsets(decorView);
|
ViewCompat.requestApplyInsets(decorView);
|
||||||
res.resolve(null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void setHidden(final boolean hidden, final Promise res) {
|
public void setHidden(final boolean hidden) {
|
||||||
final Activity activity = getCurrentActivity();
|
final Activity activity = getCurrentActivity();
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
|
FLog.w(ReactConstants.TAG, "StatusBarModule: Ignored status bar change, current activity is null.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UiThreadUtil.runOnUiThread(
|
UiThreadUtil.runOnUiThread(
|
||||||
|
@ -165,17 +159,15 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
|
||||||
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||||
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.resolve(null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void setStyle(final String style, final Promise res) {
|
public void setStyle(final String style) {
|
||||||
final Activity activity = getCurrentActivity();
|
final Activity activity = getCurrentActivity();
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
|
FLog.w(ReactConstants.TAG, "StatusBarModule: Ignored status bar change, current activity is null.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +180,6 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
|
||||||
View decorView = activity.getWindow().getDecorView();
|
View decorView = activity.getWindow().getDecorView();
|
||||||
decorView.setSystemUiVisibility(
|
decorView.setSystemUiVisibility(
|
||||||
style.equals("dark-content") ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0);
|
style.equals("dark-content") ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0);
|
||||||
res.resolve(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue