Android: on switch not called when toggle by js code

This commit is contained in:
王劲鹏
2021-03-08 11:16:12 +08:00
committed by osborn
parent 9c166da915
commit 2d5d24ac40

View File

@@ -39,6 +39,8 @@ public class SwitchNode extends ViewNode<SwitchCompat> {
private int onTintColor = 0xff52d769;
private int thumbTintColor = Color.WHITE;
private boolean checkByCodeToggle = false;
public SwitchNode(DoricContext doricContext) {
super(doricContext);
}
@@ -55,7 +57,9 @@ public class SwitchNode extends ViewNode<SwitchCompat> {
if (!prop.isBoolean()) {
return;
}
checkByCodeToggle = true;
view.setChecked(prop.asBoolean().value());
checkByCodeToggle = false;
break;
case "onSwitch":
if (!prop.isString()) {
@@ -65,6 +69,7 @@ public class SwitchNode extends ViewNode<SwitchCompat> {
view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkByCodeToggle) return;
callJSResponse(callbackId, isChecked);
}
});