Skip to content

Commit

Permalink
fix(android): text node add gesture span with gesture events
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and hippy-actions[bot] committed Jan 31, 2024
1 parent e03270d commit e24cc61
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ protected void createSpanOperationImpl(@NonNull List<SpanOperation> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -47,6 +49,17 @@ public abstract class VirtualNode {
protected String mVerticalAlign;
protected float mOpacity = 1f;

public static final HashSet<String> GESTURE_EVENTS = new HashSet<String>() {{
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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit e24cc61

Please sign in to comment.