mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-08 17:46:35 +08:00
Expose StatusBar height and fix StatusBar example - T13591448
Reviewed By: achen1 Differential Revision: D5624514 fbshipit-source-id: edc1ebe9758bd6a67e79a60128553414fb1424d3
This commit is contained in:
committed by
Facebook Github Bot
parent
66da0d27da
commit
6f60f2bf67
@@ -19,7 +19,6 @@ import android.support.v4.view.ViewCompat;
|
||||
import android.view.View;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.bridge.GuardedRunnable;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
@@ -31,9 +30,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -75,31 +72,36 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new GuardedRunnable(getReactApplicationContext()) {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void runGuarded() {
|
||||
if (animated) {
|
||||
int curColor = activity.getWindow().getStatusBarColor();
|
||||
ValueAnimator colorAnimation = ValueAnimator.ofObject(
|
||||
new ArgbEvaluator(), curColor, color);
|
||||
|
||||
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animator) {
|
||||
activity.getWindow().setStatusBarColor((Integer) animator.getAnimatedValue());
|
||||
}
|
||||
});
|
||||
colorAnimation
|
||||
.setDuration(300)
|
||||
.setStartDelay(0);
|
||||
colorAnimation.start();
|
||||
} else {
|
||||
activity.getWindow().setStatusBarColor(color);
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new GuardedRunnable(getReactApplicationContext()) {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void runGuarded() {
|
||||
activity
|
||||
.getWindow()
|
||||
.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
if (animated) {
|
||||
int curColor = activity.getWindow().getStatusBarColor();
|
||||
ValueAnimator colorAnimation =
|
||||
ValueAnimator.ofObject(new ArgbEvaluator(), curColor, color);
|
||||
|
||||
colorAnimation.addUpdateListener(
|
||||
new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animator) {
|
||||
activity
|
||||
.getWindow()
|
||||
.setStatusBarColor((Integer) animator.getAnimatedValue());
|
||||
}
|
||||
});
|
||||
colorAnimation.setDuration(300).setStartDelay(0);
|
||||
colorAnimation.start();
|
||||
} else {
|
||||
activity.getWindow().setStatusBarColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user