js: list add reload api

This commit is contained in:
pengfei.zhou 2022-08-16 17:44:03 +08:00 committed by osborn
parent 7dda15efbd
commit 3de2162ef6
12 changed files with 56 additions and 3 deletions

View File

@ -413,6 +413,24 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
return jsonArray; return jsonArray;
} }
@DoricMethod
public void reload() {
this.listAdapter.loadAnchor = -1;
// If reload,should reset native cache.
for (int index = 0; index < this.itemValues.size(); index++) {
removeSubModel(this.itemValues.valueAt(index));
}
this.itemValues.clear();
mView.post(new Runnable() {
@SuppressLint("NotifyDataSetChanged")
@Override
public void run() {
listAdapter.notifyDataSetChanged();
}
});
}
private void moveToPosition(int pos, boolean smooth) { private void moveToPosition(int pos, boolean smooth) {
if (mView.getLayoutManager() == null) { if (mView.getLayoutManager() == null) {
return; return;

View File

@ -83,8 +83,9 @@ class ListVM extends ViewModel<ListModel, ListVH> {
heightSpec: LayoutSpec.JUST, heightSpec: LayoutSpec.JUST,
}, },
height: 50, height: 50,
onClick: function () { onClick: () => {
(this as Text).height += 10 data.text += "1"
vh.list.reload(this.context)
} }
}) })
]), { ]), {

View File

@ -566,4 +566,16 @@ - (void)subNodeContentChanged:(DoricViewNode *)subNode {
[subNode.view.doricLayout apply]; [subNode.view.doricLayout apply];
[super subNodeContentChanged:subNode]; [super subNodeContentChanged:subNode];
} }
- (void)reload {
self.loadAnchor = -1;
[self.itemViewIds.allValues forEach:^(NSString *obj) {
[self removeSubModel:obj];
}];
[self.itemViewIds removeAllObjects];
dispatch_async(dispatch_get_main_queue(), ^{
self.rowCount = self.itemCount + (self.loadMore ? 1 : 0);
[self.view reloadData];
});
}
@end @end

View File

@ -2507,6 +2507,9 @@ var List = /** @class */ (function (_super) {
this.cachedViews.clear(); this.cachedViews.clear();
this.itemCount = 0; this.itemCount = 0;
}; };
List.prototype.reload = function (context) {
return this.nativeChannel(context, 'reload')();
};
List.prototype.getItem = function (itemIdx) { List.prototype.getItem = function (itemIdx) {
var view = this.renderItem(itemIdx); var view = this.renderItem(itemIdx);
view.superview = this; view.superview = this;

View File

@ -1893,6 +1893,9 @@ class List extends Superview {
this.cachedViews.clear(); this.cachedViews.clear();
this.itemCount = 0; this.itemCount = 0;
} }
reload(context) {
return this.nativeChannel(context, 'reload')();
}
getItem(itemIdx) { getItem(itemIdx) {
let view = this.renderItem(itemIdx); let view = this.renderItem(itemIdx);
view.superview = this; view.superview = this;

View File

@ -3423,6 +3423,9 @@ class List extends Superview {
this.cachedViews.clear(); this.cachedViews.clear();
this.itemCount = 0; this.itemCount = 0;
} }
reload(context) {
return this.nativeChannel(context, 'reload')();
}
getItem(itemIdx) { getItem(itemIdx) {
let view = this.renderItem(itemIdx); let view = this.renderItem(itemIdx);
view.superview = this; view.superview = this;

1
doric-js/index.d.ts vendored
View File

@ -1040,6 +1040,7 @@ declare module "doric" {
*/ */
findCompletelyVisibleItems(context: BridgeContext): Promise<number[]>; findCompletelyVisibleItems(context: BridgeContext): Promise<number[]>;
reset(): void; reset(): void;
reload(context: BridgeContext): Promise<void>;
private getItem; private getItem;
private renderBunchedItems; private renderBunchedItems;
toModel(): NativeViewModel; toModel(): NativeViewModel;

View File

@ -54,6 +54,7 @@ export declare class List extends Superview {
*/ */
findCompletelyVisibleItems(context: BridgeContext): Promise<number[]>; findCompletelyVisibleItems(context: BridgeContext): Promise<number[]>;
reset(): void; reset(): void;
reload(context: BridgeContext): Promise<void>;
private getItem; private getItem;
private renderBunchedItems; private renderBunchedItems;
toModel(): NativeViewModel; toModel(): NativeViewModel;

View File

@ -71,6 +71,9 @@ export class List extends Superview {
this.cachedViews.clear(); this.cachedViews.clear();
this.itemCount = 0; this.itemCount = 0;
} }
reload(context) {
return this.nativeChannel(context, 'reload')();
}
getItem(itemIdx) { getItem(itemIdx) {
let view = this.renderItem(itemIdx); let view = this.renderItem(itemIdx);
view.superview = this; view.superview = this;

View File

@ -116,6 +116,11 @@ export class List extends Superview {
this.cachedViews.clear() this.cachedViews.clear()
this.itemCount = 0 this.itemCount = 0
} }
reload(context: BridgeContext) {
return this.nativeChannel(context, 'reload')() as Promise<void>
}
private getItem(itemIdx: number) { private getItem(itemIdx: number) {
let view = this.renderItem(itemIdx) let view = this.renderItem(itemIdx)
view.superview = this view.superview = this

View File

@ -3500,6 +3500,9 @@ class List extends Superview {
this.cachedViews.clear(); this.cachedViews.clear();
this.itemCount = 0; this.itemCount = 0;
} }
reload(context) {
return this.nativeChannel(context, 'reload')();
}
getItem(itemIdx) { getItem(itemIdx) {
let view = this.renderItem(itemIdx); let view = this.renderItem(itemIdx);
view.superview = this; view.superview = this;

File diff suppressed because one or more lines are too long