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 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<RecyclerView> 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<RecyclerView> 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;

View File

@ -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]) {

View File

@ -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<any>