From 84e8a6e86d335ebfbb06ee897d9f4576f62172ab Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sat, 7 Dec 2019 11:08:34 +0800 Subject: [PATCH] feat:fix nested slider --- .../shader/flowlayout/FlowLayoutNode.java | 34 ++++++++++++++++--- .../java/pub/doric/shader/list/ListNode.java | 11 +++--- .../pub/doric/shader/slider/SlideAdapter.java | 2 +- .../pub/doric/shader/slider/SliderNode.java | 8 +++-- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java b/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java index 29fe3903..e7d44a06 100644 --- a/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java +++ b/doric/src/main/java/pub/doric/shader/flowlayout/FlowLayoutNode.java @@ -16,6 +16,8 @@ package pub.doric.shader.flowlayout; import android.graphics.Rect; +import android.os.SystemClock; +import android.view.MotionEvent; import android.view.View; import androidx.annotation.NonNull; @@ -41,7 +43,26 @@ public class FlowLayoutNode extends SuperNode { private final FlowAdapter flowAdapter; private final StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager( 2, - StaggeredGridLayoutManager.VERTICAL); + StaggeredGridLayoutManager.VERTICAL) { + @Override + public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) { + try { + return super.scrollVerticallyBy(dy, recycler, state); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + @Override + public void onScrollStateChanged(int state) { + try { + super.onScrollStateChanged(state); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; private int columnSpace = 0; private int rowSpace = 0; private Rect padding = new Rect(); @@ -92,10 +113,13 @@ public class FlowLayoutNode extends SuperNode { this.flowAdapter.itemCount = prop.asNumber().toInt(); break; case "renderItem": - this.flowAdapter.renderItemFuncId = prop.asString().value(); - // If reset renderItem,should reset native cache. - this.flowAdapter.itemValues.clear(); - clearSubModel(); + String funcId = prop.asString().value(); + if (!funcId.equals(this.flowAdapter.renderItemFuncId)) { + this.flowAdapter.renderItemFuncId = funcId; + // If reset renderItem,should reset native cache. + this.flowAdapter.itemValues.clear(); + clearSubModel(); + } break; case "batchCount": this.flowAdapter.batchCount = prop.asNumber().toInt(); diff --git a/doric/src/main/java/pub/doric/shader/list/ListNode.java b/doric/src/main/java/pub/doric/shader/list/ListNode.java index 3349c844..75f0da8d 100644 --- a/doric/src/main/java/pub/doric/shader/list/ListNode.java +++ b/doric/src/main/java/pub/doric/shader/list/ListNode.java @@ -85,10 +85,13 @@ public class ListNode extends SuperNode { this.listAdapter.itemCount = prop.asNumber().toInt(); break; case "renderItem": - this.listAdapter.renderItemFuncId = prop.asString().value(); - // If reset renderItem,should reset native cache. - this.listAdapter.itemValues.clear(); - clearSubModel(); + String funcId = prop.asString().value(); + if (!funcId.equals(this.listAdapter.renderItemFuncId)) { + this.listAdapter.renderItemFuncId = funcId; + // If reset renderItem,should reset native cache. + this.listAdapter.itemValues.clear(); + clearSubModel(); + } break; case "batchCount": this.listAdapter.batchCount = prop.asNumber().toInt(); diff --git a/doric/src/main/java/pub/doric/shader/slider/SlideAdapter.java b/doric/src/main/java/pub/doric/shader/slider/SlideAdapter.java index f68d38ba..31755d26 100644 --- a/doric/src/main/java/pub/doric/shader/slider/SlideAdapter.java +++ b/doric/src/main/java/pub/doric/shader/slider/SlideAdapter.java @@ -43,7 +43,7 @@ class SlideAdapter extends RecyclerView.Adapter { int itemCount = 0; int batchCount = 3; SparseArray itemValues = new SparseArray<>(); - + String renderPageFuncId; SlideAdapter(SliderNode sliderNode) { this.sliderNode = sliderNode; } diff --git a/doric/src/main/java/pub/doric/shader/slider/SliderNode.java b/doric/src/main/java/pub/doric/shader/slider/SliderNode.java index e271b298..c08756fa 100644 --- a/doric/src/main/java/pub/doric/shader/slider/SliderNode.java +++ b/doric/src/main/java/pub/doric/shader/slider/SliderNode.java @@ -137,8 +137,12 @@ public class SliderNode extends SuperNode { break; case "renderPage": // If reset renderItem,should reset native cache. - this.slideAdapter.itemValues.clear(); - clearSubModel(); + String funcId = prop.asString().value(); + if (!funcId.equals(this.slideAdapter.renderPageFuncId)) { + this.slideAdapter.itemValues.clear(); + clearSubModel(); + this.slideAdapter.renderPageFuncId = funcId; + } break; case "batchCount": this.slideAdapter.batchCount = prop.asNumber().toInt();