rn-snap-carousel-sg 1.0.0 → 1.0.1
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/Readme.md +310 -8
- package/package.json +4 -4
package/Readme.md
CHANGED
|
@@ -1,15 +1,317 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rn-snap-carousel-sg
|
|
2
2
|
|
|
3
|
-
An
|
|
3
|
+
An easy-to-use, customizable carousel component for React Native with auto-scroll, pagination, and custom rendering support.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/rn-snap-carousel-sg)
|
|
6
|
+
[](https://github.com/siddhant124/rn-snap-carousel-sg/blob/main/LICENSE)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Features
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
- ✨ Simple and intuitive API
|
|
11
|
+
- 🔄 Auto-scroll with customizable intervals
|
|
12
|
+
- 📍 Built-in pagination dots
|
|
13
|
+
- 🎨 Fully customizable styling
|
|
14
|
+
- 🖼️ Default image carousel or custom render items
|
|
15
|
+
- 📱 Responsive design
|
|
16
|
+
- ⚡ TypeScript support
|
|
17
|
+
- 🪶 Lightweight with zero dependencies
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
## Installation
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
```bash
|
|
22
|
+
npm install rn-snap-carousel-sg
|
|
23
|
+
```
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
or with yarn:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
yarn add rn-snap-carousel-sg
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Compatibility
|
|
32
|
+
|
|
33
|
+
| Package Version | React Native | React |
|
|
34
|
+
| --------------- | ------------ | --------- |
|
|
35
|
+
| 1.0.0+ | >= 0.60.0 | >= 16.8.0 |
|
|
36
|
+
|
|
37
|
+
**Recommended:**
|
|
38
|
+
|
|
39
|
+
- React Native: 0.83.1
|
|
40
|
+
- React: 19.2.0
|
|
41
|
+
|
|
42
|
+
## Basic Usage
|
|
43
|
+
|
|
44
|
+
### Simple Image Carousel
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import React from 'react';
|
|
48
|
+
import { View } from 'react-native';
|
|
49
|
+
import BasicCarousel from 'rn-snap-carousel-sg';
|
|
50
|
+
|
|
51
|
+
const App = () => {
|
|
52
|
+
const carouselData = [
|
|
53
|
+
{ image: 'https://example.com/image1.jpg' },
|
|
54
|
+
{ image: 'https://example.com/image2.jpg' },
|
|
55
|
+
{ image: 'https://example.com/image3.jpg' },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<View style={{ flex: 1, justifyContent: 'center' }}>
|
|
60
|
+
<BasicCarousel data={carouselData} />
|
|
61
|
+
</View>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default App;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Custom Render Item
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import React from 'react';
|
|
72
|
+
import { View, Text, Image, StyleSheet } from 'react-native';
|
|
73
|
+
import BasicCarousel from 'rn-snap-carousel-sg';
|
|
74
|
+
|
|
75
|
+
const App = () => {
|
|
76
|
+
const products = [
|
|
77
|
+
{ id: 1, title: 'Product 1', image: 'https://example.com/product1.jpg' },
|
|
78
|
+
{ id: 2, title: 'Product 2', image: 'https://example.com/product2.jpg' },
|
|
79
|
+
{ id: 3, title: 'Product 3', image: 'https://example.com/product3.jpg' },
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const renderProduct = (item) => (
|
|
83
|
+
<View style={styles.card}>
|
|
84
|
+
<Image source={{ uri: item.image }} style={styles.image} />
|
|
85
|
+
<Text style={styles.title}>{item.title}</Text>
|
|
86
|
+
</View>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<View style={{ flex: 1, justifyContent: 'center' }}>
|
|
91
|
+
<BasicCarousel
|
|
92
|
+
data={products}
|
|
93
|
+
renderItem={renderProduct}
|
|
94
|
+
autoScroll={true}
|
|
95
|
+
scrollInterval={4000}
|
|
96
|
+
/>
|
|
97
|
+
</View>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const styles = StyleSheet.create({
|
|
102
|
+
card: {
|
|
103
|
+
width: 350,
|
|
104
|
+
height: 200,
|
|
105
|
+
borderRadius: 12,
|
|
106
|
+
overflow: 'hidden',
|
|
107
|
+
backgroundColor: '#fff',
|
|
108
|
+
marginHorizontal: 20,
|
|
109
|
+
},
|
|
110
|
+
image: {
|
|
111
|
+
width: '100%',
|
|
112
|
+
height: 150,
|
|
113
|
+
},
|
|
114
|
+
title: {
|
|
115
|
+
padding: 10,
|
|
116
|
+
fontSize: 16,
|
|
117
|
+
fontWeight: 'bold',
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
export default App;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Advanced Usage
|
|
125
|
+
|
|
126
|
+
### Fully Customized Carousel
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import React from 'react';
|
|
130
|
+
import { View, StyleSheet } from 'react-native';
|
|
131
|
+
import BasicCarousel from 'rn-snap-carousel-sg';
|
|
132
|
+
|
|
133
|
+
const App = () => {
|
|
134
|
+
const data = [
|
|
135
|
+
{ id: 1, content: 'Slide 1' },
|
|
136
|
+
{ id: 2, content: 'Slide 2' },
|
|
137
|
+
{ id: 3, content: 'Slide 3' },
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<View style={styles.container}>
|
|
142
|
+
<BasicCarousel
|
|
143
|
+
data={data}
|
|
144
|
+
renderItem={(item) => (
|
|
145
|
+
<View style={styles.customCard}>
|
|
146
|
+
<Text style={styles.customText}>{item.content}</Text>
|
|
147
|
+
</View>
|
|
148
|
+
)}
|
|
149
|
+
autoScroll={true}
|
|
150
|
+
scrollInterval={5000}
|
|
151
|
+
showPagination={true}
|
|
152
|
+
containerStyle={styles.carouselContainer}
|
|
153
|
+
paginationContainerStyle={styles.pagination}
|
|
154
|
+
paginationDotStyle={styles.dot}
|
|
155
|
+
/>
|
|
156
|
+
</View>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const styles = StyleSheet.create({
|
|
161
|
+
container: {
|
|
162
|
+
flex: 1,
|
|
163
|
+
justifyContent: 'center',
|
|
164
|
+
backgroundColor: '#f5f5f5',
|
|
165
|
+
},
|
|
166
|
+
carouselContainer: {
|
|
167
|
+
marginVertical: 20,
|
|
168
|
+
},
|
|
169
|
+
customCard: {
|
|
170
|
+
width: 300,
|
|
171
|
+
height: 200,
|
|
172
|
+
backgroundColor: '#4CAF50',
|
|
173
|
+
borderRadius: 15,
|
|
174
|
+
justifyContent: 'center',
|
|
175
|
+
alignItems: 'center',
|
|
176
|
+
marginHorizontal: 35,
|
|
177
|
+
},
|
|
178
|
+
customText: {
|
|
179
|
+
fontSize: 24,
|
|
180
|
+
color: '#fff',
|
|
181
|
+
fontWeight: 'bold',
|
|
182
|
+
},
|
|
183
|
+
pagination: {
|
|
184
|
+
marginTop: 20,
|
|
185
|
+
},
|
|
186
|
+
dot: {
|
|
187
|
+
backgroundColor: '#4CAF50',
|
|
188
|
+
height: 10,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
export default App;
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## API Reference
|
|
196
|
+
|
|
197
|
+
### Props
|
|
198
|
+
|
|
199
|
+
| Prop | Type | Default | Description |
|
|
200
|
+
| -------------------------- | ---------------------------- | ------------ | --------------------------------------------- |
|
|
201
|
+
| `data` | `any[]` | **Required** | Array of items to display in the carousel |
|
|
202
|
+
| `renderItem` | `(item: any) => JSX.Element` | `undefined` | Custom render function for each carousel item |
|
|
203
|
+
| `autoScroll` | `boolean` | `true` | Enable/disable automatic scrolling |
|
|
204
|
+
| `scrollInterval` | `number` | `3000` | Time in milliseconds between auto-scrolls |
|
|
205
|
+
| `showPagination` | `boolean` | `true` | Show/hide pagination dots |
|
|
206
|
+
| `containerStyle` | `StyleProp<ViewStyle>` | `undefined` | Custom style for the carousel container |
|
|
207
|
+
| `paginationContainerStyle` | `StyleProp<ViewStyle>` | `undefined` | Custom style for the pagination container |
|
|
208
|
+
| `paginationDotStyle` | `StyleProp<ViewStyle>` | `undefined` | Custom style for pagination dots |
|
|
209
|
+
|
|
210
|
+
### Types
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
interface CarouselProps {
|
|
214
|
+
data: any[];
|
|
215
|
+
renderItem?: (item: any) => JSX.Element;
|
|
216
|
+
autoScroll?: boolean;
|
|
217
|
+
scrollInterval?: number;
|
|
218
|
+
showPagination?: boolean;
|
|
219
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
220
|
+
paginationContainerStyle?: StyleProp<ViewStyle>;
|
|
221
|
+
paginationDotStyle?: StyleProp<ViewStyle>;
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Examples
|
|
226
|
+
|
|
227
|
+
### Disable Auto-Scroll
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
<BasicCarousel
|
|
231
|
+
data={carouselData}
|
|
232
|
+
autoScroll={false}
|
|
233
|
+
/>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Custom Scroll Interval
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
<BasicCarousel
|
|
240
|
+
data={carouselData}
|
|
241
|
+
scrollInterval={5000} // 5 seconds
|
|
242
|
+
/>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Hide Pagination
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
<BasicCarousel
|
|
249
|
+
data={carouselData}
|
|
250
|
+
showPagination={false}
|
|
251
|
+
/>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Custom Pagination Style
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
<BasicCarousel
|
|
258
|
+
data={carouselData}
|
|
259
|
+
paginationDotStyle={{
|
|
260
|
+
backgroundColor: '#FF5722',
|
|
261
|
+
height: 12,
|
|
262
|
+
}}
|
|
263
|
+
paginationContainerStyle={{
|
|
264
|
+
marginTop: 25,
|
|
265
|
+
}}
|
|
266
|
+
/>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Default Behavior
|
|
270
|
+
|
|
271
|
+
When no `renderItem` is provided, the carousel will:
|
|
272
|
+
|
|
273
|
+
- Look for an `image` property in each data item
|
|
274
|
+
- Display the image in a rounded card
|
|
275
|
+
- Use a fallback image if no image is found
|
|
276
|
+
|
|
277
|
+
## TypeScript Support
|
|
278
|
+
|
|
279
|
+
The package is written in TypeScript and includes type definitions. Import types as needed:
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
import BasicCarousel, { CarouselProps } from "rn-snap-carousel-sg";
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Contributing
|
|
286
|
+
|
|
287
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
288
|
+
|
|
289
|
+
1. Fork the repository
|
|
290
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
291
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
292
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
293
|
+
5. Open a Pull Request
|
|
294
|
+
|
|
295
|
+
## Issues
|
|
296
|
+
|
|
297
|
+
Found a bug or have a feature request? Please open an issue on [GitHub](https://github.com/siddhant124/rn-snap-carousel-sg/issues).
|
|
298
|
+
|
|
299
|
+
## License
|
|
300
|
+
|
|
301
|
+
Apache-2.0 © [Siddhant Goyal](https://github.com/siddhant124)
|
|
302
|
+
|
|
303
|
+
## Author
|
|
304
|
+
|
|
305
|
+
**Siddhant Goyal**
|
|
306
|
+
|
|
307
|
+
- GitHub: [@siddhant124](https://github.com/siddhant124)
|
|
308
|
+
|
|
309
|
+
## Changelog
|
|
310
|
+
|
|
311
|
+
### 1.0.0
|
|
312
|
+
|
|
313
|
+
- Initial release
|
|
314
|
+
- Auto-scroll functionality
|
|
315
|
+
- Pagination support
|
|
316
|
+
- Custom render support
|
|
317
|
+
- TypeScript support
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-snap-carousel-sg",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "An easiest way to integrate carousels in your react native.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"npm",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"test": "npm run test"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"react": "
|
|
38
|
-
"react-native": "0.
|
|
37
|
+
"react": ">=16.8.0",
|
|
38
|
+
"react-native": ">=0.60.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/react": "
|
|
41
|
+
"@types/react": "*"
|
|
42
42
|
}
|
|
43
43
|
}
|