From 418b71c7a33dfd8bea40e8bd740c830a4033a537 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 23 Apr 2021 17:46:39 +0800 Subject: [PATCH] feat:List support scrollable --- .../java/pub/doric/shader/list/ListNode.java | 19 ++++++++++++++++++- doric-iOS/Pod/Classes/Shader/DoricListNode.m | 4 +++- doric-js/src/widget/list.ts | 3 +++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java b/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java index bfc27857..3ad4f96b 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/list/ListNode.java @@ -62,11 +62,14 @@ public class ListNode extends SuperNode implements IDoricScrollabl private String onScrollFuncId; private String onScrollEndFuncId; private final DoricJSDispatcher jsDispatcher = new DoricJSDispatcher(); + public ListNode(DoricContext doricContext) { super(doricContext); this.listAdapter = new ListAdapter(this); } + private boolean scrollable = true; + @Override protected void blendSubNode(JSObject subProperties) { String viewId = subProperties.getProperty("id").asString().value(); @@ -85,7 +88,15 @@ public class ListNode extends SuperNode implements IDoricScrollabl @Override protected RecyclerView build() { RecyclerView recyclerView = new RecyclerView(getContext()); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext()) { + @Override + public boolean canScrollVertically() { + if (!scrollable) { + return false; + } + return super.canScrollVertically(); + } + }); recyclerView.setAdapter(this.listAdapter); recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override @@ -145,6 +156,12 @@ public class ListNode extends SuperNode implements IDoricScrollabl @Override protected void blend(RecyclerView view, String name, final JSValue prop) { switch (name) { + case "scrollable": + if (!prop.isBoolean()) { + return; + } + this.scrollable = prop.asBoolean().value(); + break; case "itemCount": if (!prop.isNumber()) { return; diff --git a/doric-iOS/Pod/Classes/Shader/DoricListNode.m b/doric-iOS/Pod/Classes/Shader/DoricListNode.m index 4669322c..729d915d 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricListNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricListNode.m @@ -89,7 +89,9 @@ - (UITableView *)build { } - (void)blendView:(UITableView *)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 ([@"renderItem" isEqualToString:name]) { diff --git a/doric-js/src/widget/list.ts b/doric-js/src/widget/list.ts index aed86554..a3306e7c 100644 --- a/doric-js/src/widget/list.ts +++ b/doric-js/src/widget/list.ts @@ -66,6 +66,9 @@ export class List extends Superview { @Property scrolledPosition?: number + @Property + scrollable?: boolean + scrollToItem(context: BridgeContext, index: number, config?: { animated?: boolean, }) { const animated = config?.animated return this.nativeChannel(context, 'scrollToItem')({ index, animated, }) as Promise