diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/BUCK b/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/BUCK index aef3b5e02..a50072103 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/BUCK @@ -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'), diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java index c58219cdc..70b60be3b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java @@ -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); } } );