-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.tsx
More file actions
50 lines (44 loc) · 1.15 KB
/
example.tsx
File metadata and controls
50 lines (44 loc) · 1.15 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
44
45
46
47
48
49
50
/**
* 使用示例 - 仅供参考,实际使用时需要 Lynx 环境
*/
import { PullRefreshList } from './index';
// 示例数据类型
interface ItemData {
id: number;
title: string;
content: string;
}
// 模拟数据
const mockData: ItemData[] = Array.from({ length: 20 }, (_, i) => ({
id: i + 1,
title: `项目 ${i + 1}`,
content: `这是第 ${i + 1} 个项目的内容`,
}));
// 使用示例
export function Example() {
const handleRefresh = async () => {
console.log('刷新数据...');
// 模拟异步刷新
await new Promise((resolve) => setTimeout(resolve, 1000));
console.log('刷新完成');
};
const handleLoadMore = () => {
console.log('加载更多数据...');
};
return (
<PullRefreshList<ItemData>
data={mockData}
renderItem={(item) => (
<view style={{ padding: '10px', backgroundColor: '#fff', marginBottom: '8px' }}>
<text>{item.title}</text>
<text>{item.content}</text>
</view>
)}
keyExtractor={(item) => item.id}
onRefresh={handleRefresh}
onLoadMore={handleLoadMore}
hasMoreData={true}
listType="single"
/>
);
}