Add setNativeValue command to ReactCheckBoxManager

Summary:
As a part of the migration from `setNativeProps` in Fabric and Paper, we are replacing it by view commands in the Checkbox component on Android.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D18451524

fbshipit-source-id: 566f3574b85a1ae97f78b2fb95548b8529c0c92f
This commit is contained in:
Oleksandr Melnykov
2019-11-13 10:15:50 -08:00
committed by Facebook Github Bot
parent 687d3f438f
commit cd1e34d4a2
3 changed files with 35 additions and 5 deletions
@@ -11,10 +11,12 @@ import android.content.Context;
import android.content.res.ColorStateList;
import android.util.TypedValue;
import android.widget.CompoundButton;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.TintContextWrapper;
import androidx.core.widget.CompoundButtonCompat;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
@@ -80,6 +82,18 @@ public class ReactCheckBoxManager extends SimpleViewManager<ReactCheckBox> {
view.setOnCheckedChangeListener(ON_CHECKED_CHANGE_LISTENER);
}
@Override
public void receiveCommand(
@NonNull ReactCheckBox root, String commandId, @Nullable ReadableArray args) {
switch (commandId) {
case "setNativeValue":
if (args != null) {
setOn(root, args.getBoolean(0));
break;
}
}
}
private static int getThemeColor(final Context context, String colorId) {
final TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(getIdentifier(context, colorId), value, true);