CustomPullToRefresh.ets
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { PullToRefresh, PullToRefreshConfigurator } from '@ohos/pulltorefresh';
@Component
export struct CustomPullToRefresh {
@Link alldata: Object[];
scroller: Scroller = new Scroller();
@BuilderParam customList: () => void;
onRefresh: (resolve?: (value: string | PromiseLike<string>) => void) => void = () => {
}
onLoadMore: (resolve?: (value: string | PromiseLike<string>) => void) => void = () => {
}
///是否存在上拉更多
@Prop @Watch('hasMoreChange') hasMore: boolean = true
refreshConfigurator: PullToRefreshConfigurator = new PullToRefreshConfigurator().setHasLoadMore(this.hasMore);
build() {
Column(){
PullToRefresh({
data:this.alldata,
scroller:this.scroller,
refreshConfigurator:this.refreshConfigurator,
customList:()=>{
this.customList();
},
onRefresh:()=>{
return new Promise<string>((resolve, reject) => {
this.onRefresh(resolve)
});
},
onLoadMore:()=>{
return new Promise<string>((resolve, reject) => {
this.onLoadMore(resolve)
});
},
customLoad: null,
customRefresh: null,
})
}
}
hasMoreChange() {
this.refreshConfigurator.setHasLoadMore(this.hasMore)
}
}