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:
leeight 2016-11-04 07:47:30 -07:00 committed by Facebook Github Bot
parent 3683beb88a
commit b67c0c964e
2 changed files with 16 additions and 24 deletions

View File

@ -7,6 +7,7 @@ android_library(
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/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/common:common'),
react_native_target('java/com/facebook/react/module/annotations:annotations'),

View File

@ -20,29 +20,27 @@ import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
import java.util.Map;
import javax.annotation.Nullable;
import com.facebook.react.bridge.Promise;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.annotations.ReactModule;
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.
*/
@ReactModule(name = "StatusBarManager")
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";
public StatusBarModule(ReactApplicationContext reactContext) {
@ -68,10 +66,10 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
}
@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();
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;
}
@ -99,19 +97,16 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
} else {
activity.getWindow().setStatusBarColor(color);
}
res.resolve(null);
}
});
} else {
res.resolve(null);
}
}
@ReactMethod
public void setTranslucent(final boolean translucent, final Promise res) {
public void setTranslucent(final boolean translucent) {
final Activity activity = getCurrentActivity();
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;
}
@ -141,17 +136,16 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
}
ViewCompat.requestApplyInsets(decorView);
res.resolve(null);
}
});
}
}
@ReactMethod
public void setHidden(final boolean hidden, final Promise res) {
public void setHidden(final boolean hidden) {
final Activity activity = getCurrentActivity();
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;
}
UiThreadUtil.runOnUiThread(
@ -165,17 +159,15 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
res.resolve(null);
}
});
}
@ReactMethod
public void setStyle(final String style, final Promise res) {
public void setStyle(final String style) {
final Activity activity = getCurrentActivity();
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;
}
@ -188,7 +180,6 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
View decorView = activity.getWindow().getDecorView();
decorView.setSystemUiVisibility(
style.equals("dark-content") ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0);
res.resolve(null);
}
}
);