From aa844407b4d3279f06b8e9c6a3d60c8ea87350b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 15 Mar 2023 10:49:09 +0800 Subject: [PATCH] Android: add js dispatcher for refresh widget --- .../pub/doric/refresh/RefreshableNode.java | 18 ++++++++++++++++-- .../pub/doric/utils/DoricJSDispatcher.java | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/refresh/RefreshableNode.java b/doric-android/doric/src/main/java/pub/doric/refresh/RefreshableNode.java index 3026be81..d7903305 100644 --- a/doric-android/doric/src/main/java/pub/doric/refresh/RefreshableNode.java +++ b/doric-android/doric/src/main/java/pub/doric/refresh/RefreshableNode.java @@ -1,15 +1,20 @@ package pub.doric.refresh; +import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JavaValue; +import java.util.concurrent.Callable; + import pub.doric.DoricContext; +import pub.doric.async.AsyncResult; import pub.doric.extension.bridge.DoricMethod; import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPromise; import pub.doric.shader.SuperNode; import pub.doric.shader.ViewNode; +import pub.doric.utils.DoricJSDispatcher; /** * @Description: pub.doric.pullable @@ -25,6 +30,8 @@ public class RefreshableNode extends SuperNode implements Pull private String mHeaderViewId; private ViewNode mHeaderNode; + private final DoricJSDispatcher jsDispatcher = new DoricJSDispatcher(); + public RefreshableNode(DoricContext doricContext) { super(doricContext); } @@ -184,6 +191,7 @@ public class RefreshableNode extends SuperNode implements Pull @Override public void startAnimation() { + jsDispatcher.clear(); if (mHeaderNode != null) { mHeaderNode.callJSResponse("startAnimation"); } @@ -191,15 +199,21 @@ public class RefreshableNode extends SuperNode implements Pull @Override public void stopAnimation() { + jsDispatcher.clear(); if (mHeaderNode != null) { mHeaderNode.callJSResponse("stopAnimation"); } } @Override - public void setPullingDistance(float rotation) { + public void setPullingDistance(final float rotation) { if (mHeaderNode != null) { - mHeaderNode.callJSResponse("setPullingDistance", rotation); + jsDispatcher.dispatch(new Callable>() { + @Override + public AsyncResult call() throws Exception { + return mHeaderNode.callJSResponse("setPullingDistance", rotation); + } + }); } } } diff --git a/doric-android/doric/src/main/java/pub/doric/utils/DoricJSDispatcher.java b/doric-android/doric/src/main/java/pub/doric/utils/DoricJSDispatcher.java index c4668f6e..343f108a 100644 --- a/doric-android/doric/src/main/java/pub/doric/utils/DoricJSDispatcher.java +++ b/doric-android/doric/src/main/java/pub/doric/utils/DoricJSDispatcher.java @@ -84,4 +84,8 @@ public class DoricJSDispatcher implements AsyncResult.Callback { }); } } + + public void clear() { + blocks.clear(); + } }