mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-09 09:12:06 +08:00
Support progress in ProgressBarAndroid
Differential Revision: D2626321 fb-gh-sync-id: a358a1db8c8f3b4a41dc9a600ee691e6e60310f3
This commit is contained in:
committed by
facebook-github-bot-7
parent
96b76fc85f
commit
527d11ce01
@@ -17,8 +17,12 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
* Controls an enclosing ProgressBar. Exists so that the ProgressBar can be recreated if
|
||||
* the style would change.
|
||||
*/
|
||||
class ProgressBarContainerView extends FrameLayout {
|
||||
/* package */ class ProgressBarContainerView extends FrameLayout {
|
||||
private static final int MAX_PROGRESS = 1000;
|
||||
|
||||
private @Nullable Integer mColor;
|
||||
private boolean mIndeterminate = true;
|
||||
private double mProgress;
|
||||
private @Nullable ProgressBar mProgressBar;
|
||||
|
||||
public ProgressBarContainerView(Context context) {
|
||||
@@ -28,23 +32,35 @@ class ProgressBarContainerView extends FrameLayout {
|
||||
public void setStyle(@Nullable String styleName) {
|
||||
int style = ReactProgressBarViewManager.getStyleFromString(styleName);
|
||||
mProgressBar = new ProgressBar(getContext(), null, style);
|
||||
mProgressBar.setMax(MAX_PROGRESS);
|
||||
removeAllViews();
|
||||
addView(
|
||||
mProgressBar,
|
||||
new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
}
|
||||
|
||||
public void setColor(@Nullable Integer color) {
|
||||
this.mColor = color;
|
||||
}
|
||||
|
||||
public void setIndeterminate(boolean indeterminate) {
|
||||
mIndeterminate = indeterminate;
|
||||
}
|
||||
|
||||
public void setProgress(double progress) {
|
||||
mProgress = progress;
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
if (mProgressBar == null) {
|
||||
throw new JSApplicationIllegalArgumentException("setStyle() not called");
|
||||
}
|
||||
|
||||
mProgressBar.setIndeterminate(mIndeterminate);
|
||||
setColor(mProgressBar);
|
||||
mProgressBar.setProgress((int) (mProgress * MAX_PROGRESS));
|
||||
}
|
||||
|
||||
private void setColor(ProgressBar progressBar) {
|
||||
|
||||
@@ -27,6 +27,8 @@ public class ReactProgressBarViewManager extends
|
||||
BaseViewManager<ProgressBarContainerView, ProgressBarShadowNode> {
|
||||
|
||||
/* 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 REACT_CLASS = "AndroidProgressBar";
|
||||
/* package */ static final String DEFAULT_STYLE = "Large";
|
||||
@@ -51,6 +53,16 @@ public class ReactProgressBarViewManager extends
|
||||
view.setColor(color);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_INDETERMINATE)
|
||||
public void setIndeterminate(ProgressBarContainerView view, boolean indeterminate) {
|
||||
view.setIndeterminate(indeterminate);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_PROGRESS)
|
||||
public void setProgress(ProgressBarContainerView view, double progress) {
|
||||
view.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressBarShadowNode createShadowNodeInstance() {
|
||||
return new ProgressBarShadowNode();
|
||||
|
||||
Reference in New Issue
Block a user