react-native-unilist 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +516 -0
- package/lib/module/UniList.js +101 -0
- package/lib/module/UniList.js.map +1 -0
- package/lib/module/components/Card.js +94 -0
- package/lib/module/components/Card.js.map +1 -0
- package/lib/module/components/layouts/CarouselLayout.js +88 -0
- package/lib/module/components/layouts/CarouselLayout.js.map +1 -0
- package/lib/module/components/layouts/GridLayout.js +46 -0
- package/lib/module/components/layouts/GridLayout.js.map +1 -0
- package/lib/module/components/layouts/MasonryLayout.js +45 -0
- package/lib/module/components/layouts/MasonryLayout.js.map +1 -0
- package/lib/module/hooks/usePagination.js +113 -0
- package/lib/module/hooks/usePagination.js.map +1 -0
- package/lib/module/hooks/useSearch.js +92 -0
- package/lib/module/hooks/useSearch.js.map +1 -0
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/utils/theme.js +236 -0
- package/lib/module/utils/theme.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/UniList.d.ts +34 -0
- package/lib/typescript/src/UniList.d.ts.map +1 -0
- package/lib/typescript/src/components/Card.d.ts +22 -0
- package/lib/typescript/src/components/Card.d.ts.map +1 -0
- package/lib/typescript/src/components/layouts/CarouselLayout.d.ts +14 -0
- package/lib/typescript/src/components/layouts/CarouselLayout.d.ts.map +1 -0
- package/lib/typescript/src/components/layouts/GridLayout.d.ts +11 -0
- package/lib/typescript/src/components/layouts/GridLayout.d.ts.map +1 -0
- package/lib/typescript/src/components/layouts/MasonryLayout.d.ts +9 -0
- package/lib/typescript/src/components/layouts/MasonryLayout.d.ts.map +1 -0
- package/lib/typescript/src/hooks/usePagination.d.ts +23 -0
- package/lib/typescript/src/hooks/usePagination.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSearch.d.ts +20 -0
- package/lib/typescript/src/hooks/useSearch.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +9 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/theme.d.ts +73 -0
- package/lib/typescript/src/utils/theme.d.ts.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Abdul Samad
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
# react-native-unilist
|
|
2
|
+
|
|
3
|
+
**UniList** - The most powerful React Native list component that handles both FlatList and ScrollView seamlessly. This library provides everything you need to create beautiful, interactive lists with minimal code.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- **Dual Modes**: Supports both FlatList and ScrollView
|
|
8
|
+
- **Smart Switching**: Automatically chooses FlatList or ScrollView based on props
|
|
9
|
+
- **Pre-built Cards**: 5 card types with 5 design styles
|
|
10
|
+
- **Layout System**: Grid, Masonry, and Carousel layouts
|
|
11
|
+
- **Theme System**: Light, dark, and custom themes with color schemes
|
|
12
|
+
- **Pagination**: Built-in pagination with loading states
|
|
13
|
+
- **Search & Filter**: Built-in search functionality with highlighting
|
|
14
|
+
- **Spacing Support**: Easily add spacing between items
|
|
15
|
+
- **Loading States**: Support for loading indicators
|
|
16
|
+
- **Empty States**: Custom UI for empty lists
|
|
17
|
+
- **Imperative API**: Methods for programmatic scrolling
|
|
18
|
+
- **Horizontal/Vertical**: Scroll support in both directions
|
|
19
|
+
- **TypeScript Support**: Full TypeScript support
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install react-native-unilist
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
or
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
yarn add react-native-unilist
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 🎯 Quick Start
|
|
34
|
+
|
|
35
|
+
### Basic Usage
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
import React from 'react';
|
|
39
|
+
import { Text, View } from 'react-native';
|
|
40
|
+
import { UniList, ElevatedCard } from 'react-native-unilist';
|
|
41
|
+
|
|
42
|
+
const MyComponent = () => {
|
|
43
|
+
const data = [
|
|
44
|
+
{ id: 1, title: 'Card 1', subtitle: 'Subtitle 1', content: 'Content 1' },
|
|
45
|
+
{ id: 2, title: 'Card 2', subtitle: 'Subtitle 2', content: 'Content 2' },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<UniList
|
|
50
|
+
data={data}
|
|
51
|
+
renderItem={(item) => (
|
|
52
|
+
<ElevatedCard
|
|
53
|
+
title={item.title}
|
|
54
|
+
subtitle={item.subtitle}
|
|
55
|
+
cardStyle="modern"
|
|
56
|
+
>
|
|
57
|
+
<Text>{item.content}</Text>
|
|
58
|
+
</ElevatedCard>
|
|
59
|
+
)}
|
|
60
|
+
spacing={16}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 🎨 Card Components
|
|
67
|
+
|
|
68
|
+
### Available Card Types
|
|
69
|
+
|
|
70
|
+
```jsx
|
|
71
|
+
import {
|
|
72
|
+
ElevatedCard, // With shadow and elevation
|
|
73
|
+
OutlinedCard, // With border
|
|
74
|
+
FilledCard, // Solid background
|
|
75
|
+
GradientCard, // Gradient background
|
|
76
|
+
GlassCard // Glass effect
|
|
77
|
+
} from 'react-native-unilist';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Card Styles
|
|
81
|
+
|
|
82
|
+
```jsx
|
|
83
|
+
// 5 different design styles
|
|
84
|
+
<ElevatedCard cardStyle="modern"> // Clean and modern
|
|
85
|
+
<ElevatedCard cardStyle="classic"> // Traditional design
|
|
86
|
+
<ElevatedCard cardStyle="minimal"> // Minimalist approach
|
|
87
|
+
<ElevatedCard cardStyle="material"> // Material Design
|
|
88
|
+
<ElevatedCard cardStyle="neumorphic"> // Neumorphic design
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Card Usage Examples
|
|
92
|
+
|
|
93
|
+
```jsx
|
|
94
|
+
// Basic card
|
|
95
|
+
<ElevatedCard
|
|
96
|
+
title="Card Title"
|
|
97
|
+
subtitle="Card Subtitle"
|
|
98
|
+
cardStyle="modern"
|
|
99
|
+
>
|
|
100
|
+
<Text>Card content goes here</Text>
|
|
101
|
+
</ElevatedCard>
|
|
102
|
+
|
|
103
|
+
// Custom styled card
|
|
104
|
+
<GradientCard
|
|
105
|
+
title="Custom Card"
|
|
106
|
+
subtitle="With custom colors"
|
|
107
|
+
backgroundColor="#FF6B6B"
|
|
108
|
+
borderRadius={20}
|
|
109
|
+
elevation={10}
|
|
110
|
+
>
|
|
111
|
+
<Text style={{ color: 'white' }}>Custom content</Text>
|
|
112
|
+
</GradientCard>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## 📐 Layout System
|
|
116
|
+
|
|
117
|
+
### Grid Layout
|
|
118
|
+
|
|
119
|
+
```jsx
|
|
120
|
+
import { GridLayout } from 'react-native-unilist';
|
|
121
|
+
|
|
122
|
+
<GridLayout columns={2} spacing={16}>
|
|
123
|
+
<ElevatedCard title="Item 1" />
|
|
124
|
+
<ElevatedCard title="Item 2" />
|
|
125
|
+
<ElevatedCard title="Item 3" />
|
|
126
|
+
<ElevatedCard title="Item 4" />
|
|
127
|
+
</GridLayout>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Carousel Layout
|
|
131
|
+
|
|
132
|
+
```jsx
|
|
133
|
+
import { CarouselLayout } from 'react-native-unilist';
|
|
134
|
+
|
|
135
|
+
<CarouselLayout
|
|
136
|
+
autoplay={true}
|
|
137
|
+
interval={3000}
|
|
138
|
+
showDots={true}
|
|
139
|
+
itemWidth={300}
|
|
140
|
+
>
|
|
141
|
+
<ElevatedCard title="Slide 1" />
|
|
142
|
+
<ElevatedCard title="Slide 2" />
|
|
143
|
+
<ElevatedCard title="Slide 3" />
|
|
144
|
+
</CarouselLayout>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Masonry Layout
|
|
148
|
+
|
|
149
|
+
```jsx
|
|
150
|
+
import { MasonryLayout } from 'react-native-unilist';
|
|
151
|
+
|
|
152
|
+
<MasonryLayout columns={3} spacing={8}>
|
|
153
|
+
<ElevatedCard title="Item 1" />
|
|
154
|
+
<ElevatedCard title="Item 2" />
|
|
155
|
+
<ElevatedCard title="Item 3" />
|
|
156
|
+
</MasonryLayout>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 🎨 Theme System
|
|
160
|
+
|
|
161
|
+
### Using Themes
|
|
162
|
+
|
|
163
|
+
```jsx
|
|
164
|
+
import { ThemeManager, useTheme } from 'react-native-unilist';
|
|
165
|
+
|
|
166
|
+
// Set theme
|
|
167
|
+
ThemeManager.getInstance().setThemeType('dark', 'blue');
|
|
168
|
+
|
|
169
|
+
// Use theme in component
|
|
170
|
+
const MyComponent = () => {
|
|
171
|
+
const theme = useTheme();
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<ElevatedCard
|
|
175
|
+
style={{ backgroundColor: theme.colors.surface }}
|
|
176
|
+
>
|
|
177
|
+
<Text style={{ color: theme.colors.text }}>
|
|
178
|
+
Themed content
|
|
179
|
+
</Text>
|
|
180
|
+
</ElevatedCard>
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Available Themes
|
|
186
|
+
|
|
187
|
+
```jsx
|
|
188
|
+
// Theme types
|
|
189
|
+
ThemeManager.getInstance().setThemeType('light', 'blue');
|
|
190
|
+
ThemeManager.getInstance().setThemeType('dark', 'purple');
|
|
191
|
+
ThemeManager.getInstance().setThemeType('light', 'green');
|
|
192
|
+
|
|
193
|
+
// Custom theme
|
|
194
|
+
ThemeManager.getInstance().setCustomTheme({
|
|
195
|
+
primary: '#FF0000',
|
|
196
|
+
secondary: '#00FF00',
|
|
197
|
+
background: '#000000',
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## 📄 Pagination
|
|
202
|
+
|
|
203
|
+
### Using Pagination Hook
|
|
204
|
+
|
|
205
|
+
```jsx
|
|
206
|
+
import { usePagination } from 'react-native-unilist';
|
|
207
|
+
|
|
208
|
+
const MyComponent = () => {
|
|
209
|
+
const {
|
|
210
|
+
data,
|
|
211
|
+
loading,
|
|
212
|
+
hasMore,
|
|
213
|
+
loadMore,
|
|
214
|
+
refresh
|
|
215
|
+
} = usePagination({
|
|
216
|
+
pageSize: 20,
|
|
217
|
+
onLoadMore: async (page) => {
|
|
218
|
+
// Fetch data from API
|
|
219
|
+
const response = await fetch(`/api/items?page=${page}`);
|
|
220
|
+
return response.json();
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<UniList
|
|
226
|
+
data={data}
|
|
227
|
+
renderItem={(item) => <ElevatedCard title={item.title} />}
|
|
228
|
+
onEndReached={hasMore ? loadMore : undefined}
|
|
229
|
+
onEndReachedThreshold={0.5}
|
|
230
|
+
ListFooterComponent={
|
|
231
|
+
loading ? <ActivityIndicator size="large" /> : null
|
|
232
|
+
}
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 🔍 Search & Filter
|
|
239
|
+
|
|
240
|
+
### Using Search Hook
|
|
241
|
+
|
|
242
|
+
```jsx
|
|
243
|
+
import { useSearch } from 'react-native-unilist';
|
|
244
|
+
|
|
245
|
+
const MyComponent = () => {
|
|
246
|
+
const {
|
|
247
|
+
query,
|
|
248
|
+
results,
|
|
249
|
+
setQuery,
|
|
250
|
+
clearSearch
|
|
251
|
+
} = useSearch({
|
|
252
|
+
data: originalData,
|
|
253
|
+
searchFields: ['title', 'subtitle', 'content'],
|
|
254
|
+
debounceMs: 300,
|
|
255
|
+
highlightResults: true
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return (
|
|
259
|
+
<View>
|
|
260
|
+
<TextInput
|
|
261
|
+
value={query}
|
|
262
|
+
onChangeText={setQuery}
|
|
263
|
+
placeholder="Search items..."
|
|
264
|
+
/>
|
|
265
|
+
<UniList
|
|
266
|
+
data={results}
|
|
267
|
+
renderItem={(item) => <ElevatedCard title={item.title} />}
|
|
268
|
+
/>
|
|
269
|
+
</View>
|
|
270
|
+
);
|
|
271
|
+
};
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## 🎯 Advanced Usage Examples
|
|
275
|
+
|
|
276
|
+
### 1. Complete App with All Features
|
|
277
|
+
|
|
278
|
+
```jsx
|
|
279
|
+
import React, { useState } from 'react';
|
|
280
|
+
import { View, Text, TextInput, ActivityIndicator } from 'react-native';
|
|
281
|
+
import {
|
|
282
|
+
UniList,
|
|
283
|
+
ElevatedCard,
|
|
284
|
+
GridLayout,
|
|
285
|
+
usePagination,
|
|
286
|
+
useSearch,
|
|
287
|
+
ThemeManager
|
|
288
|
+
} from 'react-native-unilist';
|
|
289
|
+
|
|
290
|
+
const App = () => {
|
|
291
|
+
// Set theme
|
|
292
|
+
React.useEffect(() => {
|
|
293
|
+
ThemeManager.getInstance().setThemeType('dark', 'blue');
|
|
294
|
+
}, []);
|
|
295
|
+
|
|
296
|
+
// Pagination
|
|
297
|
+
const {
|
|
298
|
+
data,
|
|
299
|
+
loading,
|
|
300
|
+
hasMore,
|
|
301
|
+
loadMore
|
|
302
|
+
} = usePagination({
|
|
303
|
+
pageSize: 10,
|
|
304
|
+
onLoadMore: async (page) => {
|
|
305
|
+
// Simulate API call
|
|
306
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
307
|
+
return Array.from({ length: 10 }, (_, i) => ({
|
|
308
|
+
id: page * 10 + i,
|
|
309
|
+
title: `Item ${page * 10 + i}`,
|
|
310
|
+
subtitle: `Subtitle ${page * 10 + i}`,
|
|
311
|
+
content: `Content for item ${page * 10 + i}`
|
|
312
|
+
}));
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Search
|
|
317
|
+
const {
|
|
318
|
+
query,
|
|
319
|
+
results,
|
|
320
|
+
setQuery
|
|
321
|
+
} = useSearch({
|
|
322
|
+
data,
|
|
323
|
+
searchFields: ['title', 'subtitle'],
|
|
324
|
+
debounceMs: 300
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
return (
|
|
328
|
+
<View style={{ flex: 1, padding: 16 }}>
|
|
329
|
+
<TextInput
|
|
330
|
+
value={query}
|
|
331
|
+
onChangeText={setQuery}
|
|
332
|
+
placeholder="Search items..."
|
|
333
|
+
style={{ padding: 12, borderWidth: 1, borderRadius: 8, marginBottom: 16 }}
|
|
334
|
+
/>
|
|
335
|
+
|
|
336
|
+
<UniList
|
|
337
|
+
data={results}
|
|
338
|
+
renderItem={(item) => (
|
|
339
|
+
<ElevatedCard
|
|
340
|
+
title={item.title}
|
|
341
|
+
subtitle={item.subtitle}
|
|
342
|
+
cardStyle="modern"
|
|
343
|
+
>
|
|
344
|
+
<Text>{item.content}</Text>
|
|
345
|
+
</ElevatedCard>
|
|
346
|
+
)}
|
|
347
|
+
spacing={16}
|
|
348
|
+
onEndReached={hasMore ? loadMore : undefined}
|
|
349
|
+
onEndReachedThreshold={0.5}
|
|
350
|
+
ListFooterComponent={
|
|
351
|
+
loading ? (
|
|
352
|
+
<View style={{ padding: 20, alignItems: 'center' }}>
|
|
353
|
+
<ActivityIndicator size="large" />
|
|
354
|
+
</View>
|
|
355
|
+
) : null
|
|
356
|
+
}
|
|
357
|
+
/>
|
|
358
|
+
</View>
|
|
359
|
+
);
|
|
360
|
+
};
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### 2. Grid Layout with Cards
|
|
364
|
+
|
|
365
|
+
```jsx
|
|
366
|
+
import React from 'react';
|
|
367
|
+
import { View, Dimensions } from 'react-native';
|
|
368
|
+
import { UniList, ElevatedCard } from 'react-native-unilist';
|
|
369
|
+
|
|
370
|
+
const MyComponent = () => {
|
|
371
|
+
const { width } = Dimensions.get('window');
|
|
372
|
+
const cardWidth = (width - 48) / 2;
|
|
373
|
+
|
|
374
|
+
const data = Array.from({ length: 20 }, (_, i) => ({
|
|
375
|
+
id: i + 1,
|
|
376
|
+
title: `Card ${i + 1}`,
|
|
377
|
+
subtitle: `Subtitle ${i + 1}`,
|
|
378
|
+
}));
|
|
379
|
+
|
|
380
|
+
return (
|
|
381
|
+
<UniList
|
|
382
|
+
data={data}
|
|
383
|
+
renderItem={(item) => (
|
|
384
|
+
<View style={{ width: cardWidth }}>
|
|
385
|
+
<ElevatedCard
|
|
386
|
+
title={item.title}
|
|
387
|
+
subtitle={item.subtitle}
|
|
388
|
+
cardStyle="minimal"
|
|
389
|
+
style={{ margin: 8 }}
|
|
390
|
+
/>
|
|
391
|
+
</View>
|
|
392
|
+
)}
|
|
393
|
+
spacing={8}
|
|
394
|
+
contentContainerStyle={{ padding: 16 }}
|
|
395
|
+
/>
|
|
396
|
+
);
|
|
397
|
+
};
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### 3. Horizontal Carousel
|
|
401
|
+
|
|
402
|
+
```jsx
|
|
403
|
+
import React from 'react';
|
|
404
|
+
import { View, Dimensions } from 'react-native';
|
|
405
|
+
import { UniList, GlassCard } from 'react-native-unilist';
|
|
406
|
+
|
|
407
|
+
const MyComponent = () => {
|
|
408
|
+
const { width } = Dimensions.get('window');
|
|
409
|
+
const cardWidth = width * 0.8;
|
|
410
|
+
|
|
411
|
+
const data = [
|
|
412
|
+
{ id: 1, title: 'Featured 1', subtitle: 'Premium content' },
|
|
413
|
+
{ id: 2, title: 'Featured 2', subtitle: 'Premium content' },
|
|
414
|
+
{ id: 3, title: 'Featured 3', subtitle: 'Premium content' },
|
|
415
|
+
];
|
|
416
|
+
|
|
417
|
+
return (
|
|
418
|
+
<View style={{ height: 200 }}>
|
|
419
|
+
<UniList
|
|
420
|
+
data={data}
|
|
421
|
+
horizontal={true}
|
|
422
|
+
renderItem={(item) => (
|
|
423
|
+
<View style={{ width: cardWidth }}>
|
|
424
|
+
<GlassCard
|
|
425
|
+
title={item.title}
|
|
426
|
+
subtitle={item.subtitle}
|
|
427
|
+
cardStyle="modern"
|
|
428
|
+
style={{ margin: 16 }}
|
|
429
|
+
/>
|
|
430
|
+
</View>
|
|
431
|
+
)}
|
|
432
|
+
spacing={16}
|
|
433
|
+
showsHorizontalScrollIndicator={false}
|
|
434
|
+
pagingEnabled={true}
|
|
435
|
+
/>
|
|
436
|
+
</View>
|
|
437
|
+
);
|
|
438
|
+
};
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
## 📋 Props Reference
|
|
442
|
+
|
|
443
|
+
### UniListProps
|
|
444
|
+
|
|
445
|
+
| Prop | Type | Description |
|
|
446
|
+
|------|------|-------------|
|
|
447
|
+
| `data` | `ItemT[]` | Data array - triggers FlatList mode |
|
|
448
|
+
| `renderItem` | `(item: ItemT, index: number) => ReactElement` | Function to render items in FlatList mode |
|
|
449
|
+
| `children` | `ReactNode` | Static children for ScrollView mode |
|
|
450
|
+
| `spacing` | `number` | Spacing between items (in px) |
|
|
451
|
+
| `horizontal` | `boolean` | For horizontal scrolling |
|
|
452
|
+
| `ListEmptyComponent` | `ReactElement` | Custom component for empty state |
|
|
453
|
+
| `loading` | `boolean` | Loading state |
|
|
454
|
+
| `contentContainerStyle` | `StyleProp<ViewStyle>` | Custom container styling |
|
|
455
|
+
|
|
456
|
+
### CardProps
|
|
457
|
+
|
|
458
|
+
| Prop | Type | Description |
|
|
459
|
+
|------|------|-------------|
|
|
460
|
+
| `type` | `CardType` | Card type: elevated, outlined, filled, gradient, glass |
|
|
461
|
+
| `cardStyle` | `CardStyle` | Design style: modern, classic, minimal, material, neumorphic |
|
|
462
|
+
| `title` | `string` | Card title |
|
|
463
|
+
| `subtitle` | `string` | Card subtitle |
|
|
464
|
+
| `children` | `ReactNode` | Card content |
|
|
465
|
+
| `backgroundColor` | `string` | Custom background color |
|
|
466
|
+
| `borderRadius` | `number` | Custom border radius |
|
|
467
|
+
| `elevation` | `number` | Shadow elevation (Android) |
|
|
468
|
+
|
|
469
|
+
### UniListRef (Imperative API)
|
|
470
|
+
|
|
471
|
+
| Method | Parameters | Description |
|
|
472
|
+
|--------|------------|-------------|
|
|
473
|
+
| `scrollToIndex` | `{ index: number, animated?: boolean }` | Scroll to specific index (FlatList only) |
|
|
474
|
+
| `scrollToTop` | `animated?: boolean` | Scroll to top |
|
|
475
|
+
|
|
476
|
+
## 🔄 Mode Switching Logic
|
|
477
|
+
|
|
478
|
+
UniList automatically switches between two modes:
|
|
479
|
+
|
|
480
|
+
1. **FlatList Mode**: When both `data` and `renderItem` are provided
|
|
481
|
+
2. **ScrollView Mode**: When `data` is undefined and `children` are provided
|
|
482
|
+
|
|
483
|
+
## 🎨 Styling Tips
|
|
484
|
+
|
|
485
|
+
- Use `spacing` prop for consistent spacing between items
|
|
486
|
+
- Use `contentContainerStyle` for container styling
|
|
487
|
+
- Set `width` and `height` properly with `horizontal` prop
|
|
488
|
+
- Use individual item styling for custom shadows and borders
|
|
489
|
+
- Leverage the theme system for consistent colors and spacing
|
|
490
|
+
|
|
491
|
+
## 🚀 Performance Tips
|
|
492
|
+
|
|
493
|
+
- Use FlatList mode for large lists
|
|
494
|
+
- Optimize `keyExtractor` function for unique keys
|
|
495
|
+
- Use `getItemLayout` for fixed height items
|
|
496
|
+
- Use `windowSize` and `maxToRenderPerBatch` props for performance tuning
|
|
497
|
+
- Implement pagination for large datasets
|
|
498
|
+
- Use search debouncing to avoid excessive filtering
|
|
499
|
+
|
|
500
|
+
## 📱 Platform Support
|
|
501
|
+
|
|
502
|
+
- ✅ iOS
|
|
503
|
+
- ✅ Android
|
|
504
|
+
- ✅ Web (React Native Web)
|
|
505
|
+
|
|
506
|
+
## 🤝 Contributing
|
|
507
|
+
|
|
508
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
509
|
+
|
|
510
|
+
## 📄 License
|
|
511
|
+
|
|
512
|
+
MIT
|
|
513
|
+
|
|
514
|
+
---
|
|
515
|
+
|
|
516
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
|
4
|
+
import { FlatList, ScrollView, View } from 'react-native';
|
|
5
|
+
|
|
6
|
+
/** Imperative actions forwarded to parent */
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
function UniListInner({
|
|
9
|
+
data,
|
|
10
|
+
renderItem,
|
|
11
|
+
children,
|
|
12
|
+
spacing = 0,
|
|
13
|
+
horizontal = false,
|
|
14
|
+
ListEmptyComponent,
|
|
15
|
+
loading,
|
|
16
|
+
contentContainerStyle,
|
|
17
|
+
...rest
|
|
18
|
+
}, ref) {
|
|
19
|
+
const flatRef = useRef(null);
|
|
20
|
+
const scrollRef = useRef(null);
|
|
21
|
+
|
|
22
|
+
/* ---------- expose imperative API ---------- */
|
|
23
|
+
useImperativeHandle(ref, () => ({
|
|
24
|
+
scrollToIndex: ({
|
|
25
|
+
index,
|
|
26
|
+
animated = true
|
|
27
|
+
}) => {
|
|
28
|
+
if (flatRef.current) flatRef.current.scrollToIndex({
|
|
29
|
+
index,
|
|
30
|
+
animated
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
scrollToTop: (animated = true) => {
|
|
34
|
+
if (flatRef.current) flatRef.current.scrollToOffset({
|
|
35
|
+
offset: 0,
|
|
36
|
+
animated
|
|
37
|
+
});else if (scrollRef.current) scrollRef.current.scrollTo({
|
|
38
|
+
y: 0,
|
|
39
|
+
animated
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}), []);
|
|
43
|
+
|
|
44
|
+
/* ---------- item wrapper for spacing ---------- */
|
|
45
|
+
const withSpacing = render => {
|
|
46
|
+
if (!spacing) return render;
|
|
47
|
+
return info => /*#__PURE__*/_jsx(View, {
|
|
48
|
+
style: {
|
|
49
|
+
marginRight: horizontal ? spacing : 0,
|
|
50
|
+
marginBottom: horizontal ? 0 : spacing
|
|
51
|
+
},
|
|
52
|
+
children: render(info)
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/* ---------- choose mode ---------- */
|
|
57
|
+
if (data && renderItem) {
|
|
58
|
+
const listEmpty = !loading && data.length === 0 && ListEmptyComponent ? ListEmptyComponent : null;
|
|
59
|
+
return /*#__PURE__*/_jsx(FlatList, {
|
|
60
|
+
ref: flatRef,
|
|
61
|
+
data: data,
|
|
62
|
+
renderItem: withSpacing(({
|
|
63
|
+
item,
|
|
64
|
+
index
|
|
65
|
+
}) => renderItem(item, index)),
|
|
66
|
+
keyExtractor: (_, i) => i.toString(),
|
|
67
|
+
horizontal: horizontal,
|
|
68
|
+
ListEmptyComponent: listEmpty,
|
|
69
|
+
showsHorizontalScrollIndicator: false,
|
|
70
|
+
showsVerticalScrollIndicator: false,
|
|
71
|
+
contentContainerStyle: [{
|
|
72
|
+
paddingRight: horizontal ? spacing : 0,
|
|
73
|
+
paddingBottom: spacing
|
|
74
|
+
}, contentContainerStyle],
|
|
75
|
+
...rest
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* ---------- ScrollView fallback ---------- */
|
|
80
|
+
return /*#__PURE__*/_jsx(ScrollView, {
|
|
81
|
+
ref: scrollRef,
|
|
82
|
+
horizontal: horizontal,
|
|
83
|
+
showsHorizontalScrollIndicator: false,
|
|
84
|
+
showsVerticalScrollIndicator: false,
|
|
85
|
+
contentContainerStyle: [{
|
|
86
|
+
flexDirection: horizontal ? 'row' : 'column',
|
|
87
|
+
paddingRight: horizontal ? spacing : 0,
|
|
88
|
+
paddingBottom: spacing
|
|
89
|
+
}, contentContainerStyle],
|
|
90
|
+
...rest,
|
|
91
|
+
children: React.Children.map(children, (child, idx) => /*#__PURE__*/_jsx(View, {
|
|
92
|
+
style: {
|
|
93
|
+
marginRight: horizontal ? spacing : 0,
|
|
94
|
+
marginBottom: horizontal ? 0 : spacing
|
|
95
|
+
},
|
|
96
|
+
children: child
|
|
97
|
+
}, idx))
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
export const UniList = /*#__PURE__*/forwardRef(UniListInner);
|
|
101
|
+
//# sourceMappingURL=UniList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","forwardRef","useImperativeHandle","useRef","FlatList","ScrollView","View","jsx","_jsx","UniListInner","data","renderItem","children","spacing","horizontal","ListEmptyComponent","loading","contentContainerStyle","rest","ref","flatRef","scrollRef","scrollToIndex","index","animated","current","scrollToTop","scrollToOffset","offset","scrollTo","y","withSpacing","render","info","style","marginRight","marginBottom","listEmpty","length","item","keyExtractor","_","i","toString","showsHorizontalScrollIndicator","showsVerticalScrollIndicator","paddingRight","paddingBottom","flexDirection","Children","map","child","idx","UniList"],"sourceRoot":"../../src","sources":["UniList.tsx"],"mappings":"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","ignoreList":[]}
|