Android: add js dispatcher for refresh widget

This commit is contained in:
王劲鹏 2023-03-15 10:49:09 +08:00 committed by osborn
parent 52e5977d20
commit aa844407b4
2 changed files with 20 additions and 2 deletions

View File

@ -1,15 +1,20 @@
package pub.doric.refresh; package pub.doric.refresh;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JSValue;
import com.github.pengfeizhou.jscore.JavaValue; import com.github.pengfeizhou.jscore.JavaValue;
import java.util.concurrent.Callable;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.async.AsyncResult;
import pub.doric.extension.bridge.DoricMethod; import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.extension.bridge.DoricPromise; import pub.doric.extension.bridge.DoricPromise;
import pub.doric.shader.SuperNode; import pub.doric.shader.SuperNode;
import pub.doric.shader.ViewNode; import pub.doric.shader.ViewNode;
import pub.doric.utils.DoricJSDispatcher;
/** /**
* @Description: pub.doric.pullable * @Description: pub.doric.pullable
@ -25,6 +30,8 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
private String mHeaderViewId; private String mHeaderViewId;
private ViewNode<?> mHeaderNode; private ViewNode<?> mHeaderNode;
private final DoricJSDispatcher jsDispatcher = new DoricJSDispatcher();
public RefreshableNode(DoricContext doricContext) { public RefreshableNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
} }
@ -184,6 +191,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
@Override @Override
public void startAnimation() { public void startAnimation() {
jsDispatcher.clear();
if (mHeaderNode != null) { if (mHeaderNode != null) {
mHeaderNode.callJSResponse("startAnimation"); mHeaderNode.callJSResponse("startAnimation");
} }
@ -191,15 +199,21 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
@Override @Override
public void stopAnimation() { public void stopAnimation() {
jsDispatcher.clear();
if (mHeaderNode != null) { if (mHeaderNode != null) {
mHeaderNode.callJSResponse("stopAnimation"); mHeaderNode.callJSResponse("stopAnimation");
} }
} }
@Override @Override
public void setPullingDistance(float rotation) { public void setPullingDistance(final float rotation) {
if (mHeaderNode != null) { if (mHeaderNode != null) {
mHeaderNode.callJSResponse("setPullingDistance", rotation); jsDispatcher.dispatch(new Callable<AsyncResult<JSDecoder>>() {
@Override
public AsyncResult<JSDecoder> call() throws Exception {
return mHeaderNode.callJSResponse("setPullingDistance", rotation);
}
});
} }
} }
} }

View File

@ -84,4 +84,8 @@ public class DoricJSDispatcher implements AsyncResult.Callback<JSDecoder> {
}); });
} }
} }
public void clear() {
blocks.clear();
}
} }