feat:Scroller add scrollTo method

This commit is contained in:
pengfei.zhou
2020-03-03 13:10:35 +08:00
committed by osborn
parent 2927ad5679
commit 46255632ec
12 changed files with 92 additions and 11 deletions

View File

@@ -21,7 +21,9 @@ import com.github.pengfeizhou.jscore.JSValue;
import pub.doric.DoricContext;
import pub.doric.DoricScrollChangeListener;
import pub.doric.IDoricScrollable;
import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin;
import pub.doric.utils.DoricUtils;
import pub.doric.widget.HVScrollView;
/**
@@ -113,4 +115,20 @@ public class ScrollerNode extends SuperNode<HVScrollView> implements IDoricScrol
public void setScrollChangeListener(DoricScrollChangeListener listener) {
this.doricScrollChangeListener = listener;
}
@DoricMethod
public void scrollTo(JSObject params) {
boolean animated = false;
if (params.getProperty("animated").isBoolean()) {
animated = params.getProperty("animated").asBoolean().value();
}
JSObject offset = params.getProperty("offset").asObject();
if (animated) {
this.mView.smoothScrollTo(DoricUtils.dp2px(offset.getProperty("x").asNumber().toFloat()),
DoricUtils.dp2px(offset.getProperty("y").asNumber().toFloat()));
} else {
this.mView.scrollTo(DoricUtils.dp2px(offset.getProperty("x").asNumber().toFloat()),
DoricUtils.dp2px(offset.getProperty("y").asNumber().toFloat()));
}
}
}