Android: fix list item action overlapped when sub view click set

This commit is contained in:
王劲鹏 2021-05-14 11:37:56 +08:00 committed by osborn
parent 8d8c44c8f6
commit 67ee81e90e
3 changed files with 29 additions and 6 deletions

View File

@ -18,14 +18,14 @@ package pub.doric.shader;
import android.util.Log;
import android.view.ViewGroup;
import pub.doric.DoricContext;
import com.github.pengfeizhou.jscore.JSArray;
import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;
import java.util.ArrayList;
import pub.doric.DoricContext;
/**
* @Description: com.github.penfeizhou.doric.widget
* @Author: pengfei.zhou
@ -173,4 +173,8 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
mChildNodes.clear();
mChildViewIds.clear();
}
public ArrayList<ViewNode> getChildNodes() {
return mChildNodes;
}
}

View File

@ -24,12 +24,11 @@ import com.github.pengfeizhou.jscore.JSArray;
import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;
import java.util.ArrayList;
import java.util.List;
import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.shader.GroupNode;
import pub.doric.shader.StackNode;
import pub.doric.shader.ViewNode;
/**
* @Description: com.github.penfeizhou.doric.widget
@ -91,6 +90,25 @@ public class ListItemNode extends StackNode {
return true;
}
});
recursiveHandleLongClick(this);
}
}
private void recursiveHandleLongClick(GroupNode groupNode) {
for (int i = 0; i != groupNode.getChildNodes().size(); i++) {
ViewNode node = (ViewNode) groupNode.getChildNodes().get(i);
node.getView().setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
getView().performLongClick();
return false;
}
});
if (node instanceof GroupNode) {
recursiveHandleLongClick((GroupNode) node);
}
}
}
}

View File

@ -74,7 +74,8 @@ class ListVM extends ViewModel<ListModel, ListVH> {
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.JUST,
},
height: 50
height: 50,
onClick: () => {modal(context).alert(data.text)}
}), {
layoutConfig: {
widthSpec: LayoutSpec.MOST,