diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/node/TextVirtualNode.java b/renderer/native/android/src/main/java/com/tencent/renderer/node/TextVirtualNode.java index 9be83ec5047..422e3bd25e0 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/node/TextVirtualNode.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/node/TextVirtualNode.java @@ -491,7 +491,7 @@ protected void createSpanOperationImpl(@NonNull List ops, new TextShadowSpan(mShadowOffsetDx, mShadowOffsetDy, mShadowRadius, color))); } } - if (mEventTypes != null && mEventTypes.size() > 0) { + if (containGestureEvent()) { TextGestureSpan span = new TextGestureSpan(mId); span.addGestureTypes(mEventTypes); ops.add(new SpanOperation(start, end, span)); diff --git a/renderer/native/android/src/main/java/com/tencent/renderer/node/VirtualNode.java b/renderer/native/android/src/main/java/com/tencent/renderer/node/VirtualNode.java index 4ea52fa5a38..502817e8258 100644 --- a/renderer/native/android/src/main/java/com/tencent/renderer/node/VirtualNode.java +++ b/renderer/native/android/src/main/java/com/tencent/renderer/node/VirtualNode.java @@ -22,7 +22,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.tencent.mtt.hippy.annotation.HippyControllerProps; +import com.tencent.mtt.hippy.dom.node.NodeProps; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -47,6 +49,17 @@ public abstract class VirtualNode { protected String mVerticalAlign; protected float mOpacity = 1f; + public static final HashSet GESTURE_EVENTS = new HashSet() {{ + add(NodeProps.ON_LONG_CLICK); + add(NodeProps.ON_CLICK); + add(NodeProps.ON_PRESS_IN); + add(NodeProps.ON_PRESS_OUT); + add(NodeProps.ON_TOUCH_DOWN); + add(NodeProps.ON_TOUCH_MOVE); + add(NodeProps.ON_TOUCH_END); + add(NodeProps.ON_TOUCH_CANCEL); + }}; + public VirtualNode(int rootId, int id, int pid, int index) { mRootId = rootId; mId = id; @@ -92,6 +105,17 @@ public boolean hasEventType(String event) { return mEventTypes != null && mEventTypes.contains(event); } + public boolean containGestureEvent() { + if (mEventTypes != null) { + for (String event : mEventTypes) { + if (GESTURE_EVENTS.contains(event)) { + return true; + } + } + } + return false; + } + public boolean isDirty() { return mDirty; } @@ -104,7 +128,7 @@ public void markDirty() { } public void resetChildIndex(@NonNull VirtualNode child, int index) { - if (mChildren.contains(child)) { + if (mChildren != null && mChildren.contains(child)) { removeChild(child); addChildAt(child, index); }