From 056f2f041f6f4397fc1752f4aaa2f67198925cbf Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 23 Apr 2021 17:55:59 +0800 Subject: [PATCH] feat:Slider add scrollable --- .../pub/doric/shader/slider/SliderNode.java | 17 ++++++++++++++++- doric-iOS/Pod/Classes/Shader/DoricSliderNode.m | 4 +++- doric-js/src/widget/slider.ts | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java b/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java index e467fa2b..70919521 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java @@ -45,6 +45,7 @@ public class SliderNode extends SuperNode { private String onPageSlidedFuncId; private int lastPosition = 0; private int itemCount = 0; + private boolean scrollable = true; public SliderNode(DoricContext doricContext) { super(doricContext); @@ -55,7 +56,15 @@ public class SliderNode extends SuperNode { protected RecyclerView build() { RecyclerView recyclerView = new RecyclerView(getContext()); - final LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); + final LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()) { + @Override + public boolean canScrollHorizontally() { + if (!scrollable) { + return false; + } + return super.canScrollHorizontally(); + } + }; layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); recyclerView.setLayoutManager(layoutManager); final PagerSnapHelper snapHelper = new PagerSnapHelper(); @@ -146,6 +155,12 @@ public class SliderNode extends SuperNode { @Override protected void blend(RecyclerView view, String name, JSValue prop) { switch (name) { + case "scrollable": + if (!prop.isBoolean()) { + return; + } + this.scrollable = prop.asBoolean().value(); + break; case "itemCount": this.itemCount = prop.asNumber().toInt(); break; diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index b906b9ae..f1728150 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -75,7 +75,9 @@ - (UICollectionView *)build { } - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValue:(id)prop { - if ([@"itemCount" isEqualToString:name]) { + if ([@"scrollable" isEqualToString:name]) { + self.view.scrollEnabled = [prop boolValue]; + } else if ([@"itemCount" isEqualToString:name]) { self.itemCount = [prop unsignedIntegerValue]; [self.view reloadData]; } else if ([@"renderPage" isEqualToString:name]) { diff --git a/doric-js/src/widget/slider.ts b/doric-js/src/widget/slider.ts index 00ee550c..33a58ad5 100644 --- a/doric-js/src/widget/slider.ts +++ b/doric-js/src/widget/slider.ts @@ -49,6 +49,9 @@ export class Slider extends Superview { @Property loop?: boolean + @Property + scrollable?: boolean + private getItem(itemIdx: number) { let view = this.renderPage(itemIdx) view.superview = this