Add StatusBar height constant and improve implementation

Summary:This adds a `HEIGHT` constant on `StatusBar` on Android. I needed only this for now but I will work on a better status bar dimensions API later (see TODO).

It also improves the implementation to fix a bug that happened when multiple `StatusBar` components get updated in the same frame as well as remove useless calls to the `StatusBarModule` when values did not change.

Instead of calling the `StatusBarManager` immediately when the component gets updated and relying on the order of the calls that get dispatched to native we now wait at the end of the frame to send the calls to the `StatusBarManager` using `setImmediate`. To make this work properly we need to change the data structure of the props stack a little bit to store the desired transition/animation too for each value.

Finally this updates the example to only show the ones that work for the current platform.

**Test plan**
In the UIExplorer Example, in the 'StatusBar dimensions' section it should show 25 for the height of the status bar.
A
Closes https://github.com/facebook/react-native/pull/6195

Differential Revision: D3017559

fb-gh-sync-id: d6f4c6a72a2dfde83496ecc0f56dca4abaf3055e
shipit-source-id: d6f4c6a72a2dfde83496ecc0f56dca4abaf3055e
This commit is contained in:
Janic Duplessis
2016-03-17 16:53:46 -07:00
committed by Facebook Github Bot 9
parent d0caf7e48b
commit 18f38ecdc0
4 changed files with 491 additions and 244 deletions

View File

@@ -6,6 +6,7 @@ android_library(
deps = [
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/uimanager:uimanager'),
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'),

View File

@@ -7,30 +7,41 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.modules.statusbar;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.view.View;
import android.view.WindowManager;
import java.util.Map;
import javax.annotation.Nullable;
import com.facebook.react.bridge.Promise;
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.uimanager.PixelUtil;
/**
* {@link NativeModule} that allows changing the appearance of the status bar.
*/
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) {
super(reactContext);
}
@@ -40,6 +51,19 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
return "StatusBarManager";
}
@Override
public @Nullable Map<String, Object> getConstants() {
final Context context = getReactApplicationContext();
final int heightResId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
final float height = heightResId > 0 ?
PixelUtil.toDIPFromPixel(context.getResources().getDimensionPixelSize(heightResId)) :
0;
return MapBuilder.<String, Object>of(
HEIGHT_KEY, height
);
}
@ReactMethod
public void setColor(final int color, final boolean animated, final Promise res) {
final Activity activity = getCurrentActivity();