a cross-platform (
iOS
,Android
,Web
) react native carousel component
react-native-x-carousel
is a React Native component for building a cross-platform carousel.
Highlighted Features:
- Cross Platform - uniform behaviors among
iOS
,Android
andWeb
- Loop Cycle - support head-to-tail / tail-to-head loop cycle
- Auto Play - auto play with smooth transition
- Fully Customizable - customizable carousel content & pagination
$ npm install react-native-x-carousel --save
a minimally-configured carousel
import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import Carousel, { Pagination } from 'react-native-x-carousel';
const DATA = [
{ text: '#1' },
{ text: '#2' },
{ text: '#3' },
];
const App = () => {
const renderItem = data => (
<View key={data.text} style={styles.item}>
<Text>{data.text}</Text>
</View>
);
return (
<View style={styles.container}>
<Carousel
pagination={Pagination}
renderItem={renderItem}
data={DATA}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
item: {
width: 200,
height: 200,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#dbf3fa',
},
});
export default App;
Prop | Type | Default | Description |
---|---|---|---|
data |
any[] | [] |
the item data |
renderItem |
(data: any[], index: number) => void | () => {} | function for rendering each item |
loop |
boolean | false |
determine whether the loop mode is enabled or not |
autoplay |
boolean | false |
determine whether the auto play mode is enabled or not |
autoplayInterval |
number | 2000 |
delay between item transitions in milliseconds |
pagination |
() => JSX.Element | { render: () => JSX.Element } | null |
the pagination component |
Prop | Callback Params | Description |
---|---|---|
onPage |
{ prev: number, current: number } |
called when page number changes |
2 pagination components are provided as default
import Carousel, {
Pagination, // dark-colored pagination component
PaginationLight // light-colored pagination component
} from 'react-native-x-carousel';
// ...
const App = () => (
<Carousel
// ...
pagination={PaginationLight}
/>
);
Your customized pagination component will have access to the following props
Prop | Type | Default | Description |
---|---|---|---|
total |
number | 0 |
the total number of pages |
currentPage |
number | 1 |
the current page number |
The
demo
folder contains a standalone Expo project, which can be used for dev purpose.
react-native - 0.61
react-native-web - 0.11.7
react - 16.9
-
Start Expo
$ npm install $ npm start
-
Run on
simulator
- type the following command in the
Terminal
after the project is booted up w
forweb
developementa
forandroid
simulatori
foriOS
simulator
- type the following command in the
-
Run on
device
-
require the installation of corresponding
iOS client
orandroid client
on the device -
scan the QR code from
Terminal
using the device
-
-
More on
Expo Guide
- scaffolded by react-native-component-cli
MIT