feat:List support scrollable

This commit is contained in:
pengfei.zhou 2021-04-23 17:46:39 +08:00 committed by osborn
parent 4cc67a463d
commit 418b71c7a3
3 changed files with 24 additions and 2 deletions

View File

@ -62,11 +62,14 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
private String onScrollFuncId; private String onScrollFuncId;
private String onScrollEndFuncId; private String onScrollEndFuncId;
private final DoricJSDispatcher jsDispatcher = new DoricJSDispatcher(); private final DoricJSDispatcher jsDispatcher = new DoricJSDispatcher();
public ListNode(DoricContext doricContext) { public ListNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
this.listAdapter = new ListAdapter(this); this.listAdapter = new ListAdapter(this);
} }
private boolean scrollable = true;
@Override @Override
protected void blendSubNode(JSObject subProperties) { protected void blendSubNode(JSObject subProperties) {
String viewId = subProperties.getProperty("id").asString().value(); String viewId = subProperties.getProperty("id").asString().value();
@ -85,7 +88,15 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
@Override @Override
protected RecyclerView build() { protected RecyclerView build() {
RecyclerView recyclerView = new RecyclerView(getContext()); 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.setAdapter(this.listAdapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
@ -145,6 +156,12 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
@Override @Override
protected void blend(RecyclerView view, String name, final JSValue prop) { protected void blend(RecyclerView view, String name, final JSValue prop) {
switch (name) { switch (name) {
case "scrollable":
if (!prop.isBoolean()) {
return;
}
this.scrollable = prop.asBoolean().value();
break;
case "itemCount": case "itemCount":
if (!prop.isNumber()) { if (!prop.isNumber()) {
return; return;

View File

@ -89,7 +89,9 @@ - (UITableView *)build {
} }
- (void)blendView:(UITableView *)view forPropName:(NSString *)name propValue:(id)prop { - (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.itemCount = [prop unsignedIntegerValue];
[self.view reloadData]; [self.view reloadData];
} else if ([@"renderItem" isEqualToString:name]) { } else if ([@"renderItem" isEqualToString:name]) {

View File

@ -66,6 +66,9 @@ export class List extends Superview {
@Property @Property
scrolledPosition?: number scrolledPosition?: number
@Property
scrollable?: boolean
scrollToItem(context: BridgeContext, index: number, config?: { animated?: boolean, }) { scrollToItem(context: BridgeContext, index: number, config?: { animated?: boolean, }) {
const animated = config?.animated const animated = config?.animated
return this.nativeChannel(context, 'scrollToItem')({ index, animated, }) as Promise<any> return this.nativeChannel(context, 'scrollToItem')({ index, animated, }) as Promise<any>