@@ -3,38 +3,33 @@ QuickList 快速请求列表
33
44快速完成上拉下拉请求列表。
55
6- ![ ] ( https://user-images.githubusercontent.com/66067296/140003953-6d3c5a99-a656-4bd3-a1e9-3711550cb87d.gif ) <!-- rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
7-
86### 基础示例
97
10- <!-- DemoStart-->
11- ``` jsx
8+ ``` jsx mdx:preview
129import React , { useRef , useState } from ' react' ;
1310import { SafeAreaView , Image , View , Text } from ' react-native' ;
14- import { QuickList , List } from ' @uiw/react-native' ;
11+ import QuickList from ' @uiw/react-native/lib/QuickList' ;
12+ import List from ' @uiw/react-native/lib/List' ;
1513
16- const imageUrl = ' https://c-ssl.duitang.com/uploads/item/202004/13/20200413013923_25wds.jpeg'
1714
1815const defaultData = [
19- { name: ' @uiw/react-native QuickList' , id: 1 , img : imageUrl },
20- { name: ' @uiw/react-native QuickList' , id: 2 , img : imageUrl },
21- { name: ' @uiw/react-native QuickList' , id: 3 , img : imageUrl },
22- { name: ' @uiw/react-native QuickList' , id: 4 , img : imageUrl },
23- { name: ' @uiw/react-native QuickList' , id: 5 , img : imageUrl },
24- { name: ' @uiw/react-native QuickList' , id: 6 , img : imageUrl },
25- { name: ' @uiw/react-native QuickList' , id: 7 , img : imageUrl },
26- { name: ' @uiw/react-native QuickList' , id: 8 , img : imageUrl },
27- { name: ' @uiw/react-native QuickList' , id: 9 , img : imageUrl },
28- { name: ' @uiw/react-native QuickList' , id: 10 , img : imageUrl },
16+ { name: ' @uiw/react-native QuickList' , id: 1 },
17+ { name: ' @uiw/react-native QuickList' , id: 2 },
18+ { name: ' @uiw/react-native QuickList' , id: 3 },
19+ { name: ' @uiw/react-native QuickList' , id: 4 },
20+ { name: ' @uiw/react-native QuickList' , id: 5 },
21+ { name: ' @uiw/react-native QuickList' , id: 6 },
22+ { name: ' @uiw/react-native QuickList' , id: 7 },
23+ { name: ' @uiw/react-native QuickList' , id: 8 },
24+ { name: ' @uiw/react-native QuickList' , id: 9 },
25+ { name: ' @uiw/react-native QuickList' , id: 10 },
2926];
3027
3128const QuickListDemo = (props ) => {
3229 const baseRef = useRef ();
3330 const [total , setTotal ] = useState (0 )
3431 const [data , setData ] = useState ([])
35-
3632 const sleep = (time ) => new Promise ((resolve ) => setTimeout (() => resolve (' ' ), time))
37-
3833 // 模拟请求
3934 const fethList = async (params ) => {
4035 const { page , pageSize } = params
@@ -46,8 +41,7 @@ const QuickListDemo = (props) => {
4641 for (let i = 0 ; i < pageSize; i++ ) {
4742 const id = (data .length + 1 / 10 * pageSize) + i
4843 const name = ` @uiw/react-native QuickList` ;
49- const img = imageUrl
50- let obj = { name, id,img }
44+ let obj = { name, id }
5145 fetchData .push (obj)
5246 }
5347 let newData = [... data, ... fetchData]
@@ -57,17 +51,11 @@ const QuickListDemo = (props) => {
5751 setTotal (40 )
5852 }
5953 // 列表渲染
60- const ListItem = (item : any ) => {
54+ const ListItem = (item ) => {
6155 return (
6256 < List flat= {false }>
6357 < View
6458 style= {{ padding: 10 , display: " flex" , alignItems: " center" , flexDirection: " row" }}>
65- < Image
66- source= {{
67- uri: item .img ,
68- }}
69- style= {{ height: 70 , width: 70 , borderRadius: 50 }}
70- / >
7159 < View style= {{ marginLeft: 10 }}>
7260 < Text style= {{ marginBottom: 5 , fontSize: 18 }}> react- native< / Text >
7361 < Text style= {{ color: " #808080" }}> {item .name }< / Text >
@@ -78,7 +66,7 @@ const QuickListDemo = (props) => {
7866 }
7967
8068 return (
81- < SafeAreaView style= {{ flex : 1 }}>
69+ < SafeAreaView style= {{ height : 300 }}>
8270 < QuickList
8371 ref= {baseRef}
8472 onFetch= {fethList}
@@ -92,24 +80,16 @@ const QuickListDemo = (props) => {
9280}
9381export default QuickListDemo
9482```
95- <!-- End-->
9683
9784### Props
9885
99- ``` ts
100- interface QuickListProps <ItemT > extends FlatListProps <ItemT > {
101- onFetch: (params : any ) => void // 请求的接口函数
102- data: Array <any >, // 数据源
103- renderItem: ListRenderItem <any >, // 从data列表中获取一个项目并将其渲染到列表中
104- keyId: string | number ,// 唯一健
105- emptyView? : void | any ,// 当列表为空时呈现
106- pageSize? : number , // 每次加载数据条数
107- total: number , // 总条数
108- style? : Object ,// 样式
109- }
110-
111- export type QuickListComponent <ItemT = any > = (
112- props : QuickListProps <ItemT >,
113- ref ? : Ref <FlatList <ItemT >> | any
114- ) => React .ReactElement
115- ` ` `
86+ | 属性 | 说明 | 类型 | 默认值 |
87+ | --- | --- | --- | --- |
88+ | onFetch | 请求的接口函数) | ` (params: any) => void ` | - |
89+ | data | 数据 | ` Array<any> ` | [ ] |
90+ | renderItem | 从data列表中获取一个项目并将其渲染到列表中 | ` ListRenderItem<any> ` | - |
91+ | keyId | 唯一健 | `string | number` | - |
92+ | emptyView | 当列表为空时呈现 | ` () => React.ReactNode ` | - |
93+ | pageSize | 每次加载数据条数 | ` number ` | - |
94+ | total | 总条数 | ` number ` | - |
95+ | style | 样式 | ` Object ` | - |
0 commit comments