A easy to use image slider for React Native
npm install react-native-image-sliderA quick and easy image slider for react native.
!GIF
``bash`
npm install react-native-image-slider --save`
orbash`
yarn add react-native-image-slider
`javascript
import ImageSlider from 'react-native-image-slider';
// ...
render() {
return (
'http://placeimg.com/640/480/any',
'http://placeimg.com/640/480/any'
]}/>)
}
`
`javascript
class Example extends Component<{}> {
render() {
const images = [
'https://placeimg.com/640/640/nature',
'https://placeimg.com/640/640/people',
'https://placeimg.com/640/640/animals',
'https://placeimg.com/640/640/beer',
];
return (
autoPlayWithInterval={3000}
images={images}
customSlide={({ index, item, style, width }) => (
// It's important to put style here because it's got offset inside
)}
customButtons={(position, move) => (
{images.map((image, index) => {
return (
underlayColor="#ccc"
onPress={() => move(index)}
style={styles.button}
>
{index + 1}
);
})}
)}
/>
);
}
}
`
rendered images
function returns custom pagination buttons component, it's got position index and move to position function as arguments
function returns Node with arguments index - images list index, item - anything you pass inside images prop, style - for top component of your custom slide, width` - calculated slide width
activates autoplay when passed (it uses milliseconds)
[BUGGY ON ANDROID] loops scroll of images, but in one direction only
[IOS ONLY] same as loop, but does it in any direction
called when the current position is changed
used for controlled components
returns an object with image url and index of image pressed
styles ScrollView inside ImageSlider, you may pass height here (100% by default)
MIT