Use generated Java delegate for setting properties on ReactSwitchManager
Summary: This diff migrates `ReactSwtichManager` to use the generated `ReactSwtichManagerDelegate` for setting its properties. Reviewed By: TheSavior Differential Revision: D17395067 fbshipit-source-id: 1489c5d08cef860030ecbd23ef19bd8de1328d71
This commit is contained in:
Родитель
81f567d4aa
Коммит
5cfe588993
|
@ -30,7 +30,7 @@ type NativeProps = $ReadOnly<{|
|
|||
|
||||
// Props
|
||||
disabled?: WithDefault<boolean, false>,
|
||||
enabled?: WithDefault<boolean, false>,
|
||||
enabled?: WithDefault<boolean, true>,
|
||||
thumbColor?: ?ColorValue,
|
||||
trackColorForFalse?: ?ColorValue,
|
||||
trackColorForTrue?: ?ColorValue,
|
||||
|
|
|
@ -26,7 +26,7 @@ public class AndroidSwitchManagerDelegate<T extends View, U extends BaseViewMana
|
|||
mViewManager.setDisabled(view, value == null ? false : (boolean) value);
|
||||
break;
|
||||
case "enabled":
|
||||
mViewManager.setEnabled(view, value == null ? false : (boolean) value);
|
||||
mViewManager.setEnabled(view, value == null ? true : (boolean) value);
|
||||
break;
|
||||
case "thumbColor":
|
||||
mViewManager.setThumbColor(view, value == null ? null : ((Double) value).intValue());
|
||||
|
|
|
@ -22,5 +22,6 @@ rn_android_library(
|
|||
react_native_target("java/com/facebook/react/common:common"),
|
||||
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"),
|
||||
],
|
||||
)
|
||||
|
|
|
@ -16,15 +16,19 @@ import com.facebook.react.uimanager.LayoutShadowNode;
|
|||
import com.facebook.react.uimanager.SimpleViewManager;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewManagerDelegate;
|
||||
import com.facebook.react.uimanager.ViewProps;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.viewmanagers.AndroidSwitchManagerDelegate;
|
||||
import com.facebook.react.viewmanagers.AndroidSwitchManagerInterface;
|
||||
import com.facebook.yoga.YogaMeasureFunction;
|
||||
import com.facebook.yoga.YogaMeasureMode;
|
||||
import com.facebook.yoga.YogaMeasureOutput;
|
||||
import com.facebook.yoga.YogaNode;
|
||||
|
||||
/** View manager for {@link ReactSwitch} components. */
|
||||
public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
||||
public class ReactSwitchManager extends SimpleViewManager<ReactSwitch>
|
||||
implements AndroidSwitchManagerInterface<ReactSwitch> {
|
||||
|
||||
public static final String REACT_CLASS = "AndroidSwitch";
|
||||
|
||||
|
@ -78,6 +82,12 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
|||
}
|
||||
};
|
||||
|
||||
private final ViewManagerDelegate<ReactSwitch> mDelegate;
|
||||
|
||||
public ReactSwitchManager() {
|
||||
mDelegate = new AndroidSwitchManagerDelegate<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return REACT_CLASS;
|
||||
|
@ -100,21 +110,25 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "disabled", defaultBoolean = false)
|
||||
public void setDisabled(ReactSwitch view, boolean disabled) {
|
||||
view.setEnabled(!disabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = ViewProps.ENABLED, defaultBoolean = true)
|
||||
public void setEnabled(ReactSwitch view, boolean enabled) {
|
||||
view.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = ViewProps.ON)
|
||||
public void setOn(ReactSwitch view, boolean on) {
|
||||
this.setValue(view, on);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "value")
|
||||
public void setValue(ReactSwitch view, boolean value) {
|
||||
// we set the checked change listener to null and then restore it so that we don't fire an
|
||||
|
@ -124,26 +138,31 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
|||
view.setOnCheckedChangeListener(ON_CHECKED_CHANGE_LISTENER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "thumbTintColor", customType = "Color")
|
||||
public void setThumbTintColor(ReactSwitch view, @Nullable Integer color) {
|
||||
this.setThumbColor(view, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "thumbColor", customType = "Color")
|
||||
public void setThumbColor(ReactSwitch view, @Nullable Integer color) {
|
||||
view.setThumbColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "trackColorForFalse", customType = "Color")
|
||||
public void setTrackColorForFalse(ReactSwitch view, @Nullable Integer color) {
|
||||
view.setTrackColorForFalse(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "trackColorForTrue", customType = "Color")
|
||||
public void setTrackColorForTrue(ReactSwitch view, @Nullable Integer color) {
|
||||
view.setTrackColorForTrue(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ReactProp(name = "trackTintColor", customType = "Color")
|
||||
public void setTrackTintColor(ReactSwitch view, @Nullable Integer color) {
|
||||
view.setTrackColor(color);
|
||||
|
@ -153,4 +172,9 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
|||
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactSwitch view) {
|
||||
view.setOnCheckedChangeListener(ON_CHECKED_CHANGE_LISTENER);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewManagerDelegate<ReactSwitch> getDelegate() {
|
||||
return mDelegate;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче