Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/disallow intercept touch event #3732

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class NodeProps {
public static final String ON_TOUCH_CANCEL = "touchcancel";
public static final String ON_INTERCEPT_TOUCH_EVENT = "onInterceptTouchEvent";
public static final String ON_INTERCEPT_PULL_UP_EVENT = "onInterceptPullUpEvent";
public static final String DISALLOW_INTERCEPT_TOUCH_EVENT = "disallowInterceptTouchEvent";
public static final String ON_ATTACHED_TO_WINDOW = "attachedtowindow";
public static final String ON_DETACHED_FROM_WINDOW = "detachedfromwindow";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.tencent.mtt.hippy.views.view;

import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.tencent.mtt.hippy.dom.node.NodeProps;
Expand All @@ -36,6 +37,7 @@ public class HippyViewGroup extends FlatViewGroup implements HippyViewBase {
float mDownX = 0;
float mDownY = 0;
boolean isHandlePullUp = false;
private boolean mDisallowInterceptTouchEvent = false;
private ViewConfiguration mViewConfiguration;
@Nullable
protected NativeGestureDispatcher mGestureDispatcher;
Expand Down Expand Up @@ -73,6 +75,10 @@ public void setOverflow(String overflow) {
setOverflow(overflow, this);
}

public void setDisallowInterceptTouchEvent(boolean disallow) {
mDisallowInterceptTouchEvent = disallow;
}

public static void setOverflow(@NonNull String overflow, @NonNull ViewGroup viewGroup) {
switch (overflow) {
case NodeProps.VISIBLE:
Expand All @@ -91,6 +97,12 @@ public static void setOverflow(@NonNull String overflow, @NonNull ViewGroup view
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction() & MotionEvent.ACTION_MASK;
if (action == MotionEvent.ACTION_DOWN) {
if (mDisallowInterceptTouchEvent) {
ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
}
}
mDownX = ev.getX();
mDownY = ev.getY();
isHandlePullUp = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public void setOverflow(HippyViewGroup viewGroup, String overflow) {
viewGroup.setOverflow(overflow);
}

@HippyControllerProps(name = NodeProps.DISALLOW_INTERCEPT_TOUCH_EVENT, defaultType = HippyControllerProps.BOOLEAN)
public void setDisallowInterceptTouchEvent(HippyViewGroup view, boolean disallow) {
view.setDisallowInterceptTouchEvent(disallow);
}

@SuppressWarnings("deprecation")
@Override
public void dispatchFunction(@NonNull HippyViewGroup viewGroup, @NonNull String functionName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.tencent.renderer;

import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand All @@ -24,6 +25,7 @@
import com.tencent.mtt.hippy.serialization.nio.writer.SafeHeapWriter;
import com.tencent.mtt.hippy.serialization.string.InternalizedStringTable;
import com.tencent.mtt.hippy.utils.PixelUtil;
import com.tencent.mtt.hippy.utils.UIThreadUtils;
import com.tencent.renderer.annotation.CalledByNative;
import com.tencent.renderer.serialization.Deserializer;
import com.tencent.renderer.serialization.Serializer;
Expand Down Expand Up @@ -351,7 +353,18 @@ public void onSizeChanged(int rootId, int nodeId, int width, int height, boolean
* @param nodeId the dom node id
* @param params parameters to be return to js
*/
public void doPromiseCallBack(int result, long callbackId, @NonNull String functionName,
public void doPromiseCallBack(final int result, final long callbackId, @NonNull final String functionName,
final int rootId, final int nodeId, @Nullable final Object params) {
if (UIThreadUtils.isOnUiThread()) {
doPromiseCallBackImpl(result, callbackId, functionName, rootId, nodeId, params);
} else {
UIThreadUtils.runOnUiThread(
() -> doPromiseCallBackImpl(result, callbackId, functionName, rootId, nodeId, params));
}
}

@MainThread
private void doPromiseCallBackImpl(int result, long callbackId, @NonNull String functionName,
int rootId, int nodeId, @Nullable Object params) {
byte[] bytes = null;
int offset = 0;
Expand All @@ -375,7 +388,17 @@ public void doPromiseCallBack(int result, long callbackId, @NonNull String funct
length);
}

public void dispatchEvent(int rootId, int nodeId, @NonNull String eventName,
public void dispatchEvent(final int rootId, final int nodeId, @NonNull final String eventName,
@Nullable final Object params, final boolean useCapture, final boolean useBubble) {
if (UIThreadUtils.isOnUiThread()) {
dispatchEventImpl(rootId, nodeId, eventName, params, useCapture, useBubble);
} else {
UIThreadUtils.runOnUiThread(
() -> dispatchEventImpl(rootId, nodeId, eventName, params, useCapture, useBubble));
}
}

private void dispatchEventImpl(int rootId, int nodeId, @NonNull String eventName,
@Nullable Object params, boolean useCapture, boolean useBubble) {
byte[] bytes = null;
int offset = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,18 @@ public TextImageSpan(Drawable drawable, String source, @NonNull ImageVirtualNode
}

public void setUrl(@Nullable final String url) {
if (!TextUtils.isEmpty(url)) {
if (TextUtils.isEmpty(url)) {
return;
}
if (UIThreadUtils.isOnUiThread()) {
loadImageWithUrl(url);
} else {
UIThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
loadImageWithUrl(url);
}
});
}
}

Expand Down
Loading