mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 17:30:38 +08:00
Cross platform ActivityIndicator
Summary: The API for `ActivityIndiatorIOS` and `ProgressBarAndroid` is very similar and can be merged in a cross platform component that displays a circular indeterminate loading indicator. This deprecates `ActivityIndiatorIOS` and non-horizontal `ProgressBarAndroid` in favor of this new component. **Test plan (required)** Tested with the ActivityIndicator example in UIExplorer on android and ios. Also made sure that `ActivityIndicatorIOS` still works and displays a deprecation warning. Also tested that `ProgressBarAndroid` with `indeterminate == true` and `styleAttr != 'Horizontal'` displays a deprecation warning. Closes https://github.com/facebook/react-native/pull/6897 Differential Revision: D3351607 Pulled By: dmmiller fbshipit-source-id: b107ce99d966359003e8b3118cd97b90fa1d3d7d
This commit is contained in:
committed by
Facebook Github Bot 1
parent
98dd91825f
commit
26e8426248
@@ -7,6 +7,7 @@ import javax.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ProgressBar;
|
||||
@@ -22,6 +23,7 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
|
||||
private @Nullable Integer mColor;
|
||||
private boolean mIndeterminate = true;
|
||||
private boolean mAnimating = true;
|
||||
private double mProgress;
|
||||
private @Nullable ProgressBar mProgressBar;
|
||||
|
||||
@@ -53,6 +55,10 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
mProgress = progress;
|
||||
}
|
||||
|
||||
public void setAnimating(boolean animating) {
|
||||
mAnimating = animating;
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
if (mProgressBar == null) {
|
||||
throw new JSApplicationIllegalArgumentException("setStyle() not called");
|
||||
@@ -61,6 +67,11 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
mProgressBar.setIndeterminate(mIndeterminate);
|
||||
setColor(mProgressBar);
|
||||
mProgressBar.setProgress((int) (mProgress * MAX_PROGRESS));
|
||||
if (mAnimating) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void setColor(ProgressBar progressBar) {
|
||||
|
||||
@@ -32,6 +32,7 @@ public class ReactProgressBarViewManager extends
|
||||
/* package */ static final String PROP_STYLE = "styleAttr";
|
||||
/* package */ static final String PROP_INDETERMINATE = "indeterminate";
|
||||
/* package */ static final String PROP_PROGRESS = "progress";
|
||||
/* package */ static final String PROP_ANIMATING = "animating";
|
||||
|
||||
/* package */ static final String REACT_CLASS = "AndroidProgressBar";
|
||||
/* package */ static final String DEFAULT_STYLE = "Normal";
|
||||
@@ -79,6 +80,11 @@ public class ReactProgressBarViewManager extends
|
||||
view.setProgress(progress);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_ANIMATING)
|
||||
public void setAnimating(ProgressBarContainerView view, boolean animating) {
|
||||
view.setAnimating(animating);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressBarShadowNode createShadowNodeInstance() {
|
||||
return new ProgressBarShadowNode();
|
||||
|
||||
Reference in New Issue
Block a user