Use generated Java delegate for setting properties on ReactProgressBarViewManager

Summary: This diff migrates `ReactProgressBarViewManager` to use the generated `AndroidProgressBarManagerDelegate` for setting its properties.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D17315619

fbshipit-source-id: 6293c6fc18567a934b6f3dce9b77abcc408052d8
This commit is contained in:
Oleksandr Melnykov
2019-09-23 07:18:09 -07:00
committed by Facebook Github Bot
parent 23557d1f9a
commit 2e7545cf7e
5 changed files with 35 additions and 6 deletions
@@ -32,7 +32,7 @@ public class AndroidProgressBarManagerDelegate<T extends View, U extends BaseVie
mViewManager.setIndeterminate(view, value == null ? false : (boolean) value);
break;
case "progress":
mViewManager.setProgress(view, value == null ? 0f : ((Double) value).floatValue());
mViewManager.setProgress(view, value == null ? 0f : ((Double) value).doubleValue());
break;
case "animating":
mViewManager.setAnimating(view, value == null ? true : (boolean) value);
@@ -16,7 +16,7 @@ public interface AndroidProgressBarManagerInterface<T extends View> {
void setStyleAttr(T view, @Nullable String value);
void setTypeAttr(T view, @Nullable String value);
void setIndeterminate(T view, boolean value);
void setProgress(T view, float value);
void setProgress(T view, double value);
void setAnimating(T view, boolean value);
void setColor(T view, @Nullable Integer value);
void setTestID(T view, @Nullable String value);
@@ -17,5 +17,6 @@ rn_android_library(
react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
react_native_target("java/com/facebook/react/viewmanagers:viewmanagers"),
],
)
@@ -13,8 +13,11 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.BaseViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewManagerDelegate;
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.viewmanagers.AndroidProgressBarManagerDelegate;
import com.facebook.react.viewmanagers.AndroidProgressBarManagerInterface;
/**
* Manages instances of ProgressBar. ProgressBar is wrapped in a ProgressBarContainerView because
@@ -24,7 +27,8 @@ import com.facebook.react.uimanager.annotations.ReactProp;
*/
@ReactModule(name = ReactProgressBarViewManager.REACT_CLASS)
public class ReactProgressBarViewManager
extends BaseViewManager<ProgressBarContainerView, ProgressBarShadowNode> {
extends BaseViewManager<ProgressBarContainerView, ProgressBarShadowNode>
implements AndroidProgressBarManagerInterface<ProgressBarContainerView> {
public static final String REACT_CLASS = "AndroidProgressBar";
@@ -37,6 +41,8 @@ public class ReactProgressBarViewManager
private static Object sProgressBarCtorLock = new Object();
private final ViewManagerDelegate<ProgressBarContainerView> mDelegate;
/**
* We create ProgressBars on both the UI and shadow threads. There is a race condition in the
* ProgressBar constructor that may cause crashes when two ProgressBars are constructed at the
@@ -48,6 +54,10 @@ public class ReactProgressBarViewManager
}
}
public ReactProgressBarViewManager() {
mDelegate = new AndroidProgressBarManagerDelegate<>(this);
}
@Override
public String getName() {
return REACT_CLASS;
@@ -58,31 +68,44 @@ public class ReactProgressBarViewManager
return new ProgressBarContainerView(context);
}
@Override
@ReactProp(name = PROP_STYLE)
public void setStyle(ProgressBarContainerView view, @Nullable String styleName) {
public void setStyleAttr(ProgressBarContainerView view, @Nullable String styleName) {
view.setStyle(styleName);
}
@Override
@ReactProp(name = ViewProps.COLOR, customType = "Color")
public void setColor(ProgressBarContainerView view, @Nullable Integer color) {
view.setColor(color);
}
@Override
@ReactProp(name = PROP_INDETERMINATE)
public void setIndeterminate(ProgressBarContainerView view, boolean indeterminate) {
view.setIndeterminate(indeterminate);
}
@Override
@ReactProp(name = PROP_PROGRESS)
public void setProgress(ProgressBarContainerView view, double progress) {
view.setProgress(progress);
}
@Override
@ReactProp(name = PROP_ANIMATING)
public void setAnimating(ProgressBarContainerView view, boolean animating) {
view.setAnimating(animating);
}
@Override
public void setTestID(ProgressBarContainerView view, @Nullable String value) {
super.setTestId(view, value);
}
@Override
public void setTypeAttr(ProgressBarContainerView view, @Nullable String value) {}
@Override
public ProgressBarShadowNode createShadowNodeInstance() {
return new ProgressBarShadowNode();
@@ -103,6 +126,11 @@ public class ReactProgressBarViewManager
view.apply();
}
@Override
protected ViewManagerDelegate<ProgressBarContainerView> getDelegate() {
return mDelegate;
}
/* package */ static int getStyleFromString(@Nullable String styleStr) {
if (styleStr == null) {
throw new JSApplicationIllegalArgumentException(