Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

react-native-image-slider

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-image-slider

A easy to use image slider for React Native

Source
npmnpm
Version
1.1.2
Version published
Weekly downloads
468
25.13%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-image-slider

A quick and easy image slider for react native.

GIF

Installation

npm install react-native-image-slider --save

Usage

import ImageSlider from 'react-native-image-slider';

// ...

render() {
    return (<ImageSlider images={[
        'http://placeimg.com/640/480/any',
        'http://placeimg.com/640/480/any',
        'http://placeimg.com/640/480/any'
    ]}/>)
}

To keep the height from shifting, we use a static height. If you want to change the height, simply pass a height to the component.

Props

  • height: controls the height. By default the height is static, is this if you want the height to change
  • onPositionChanged: called when the current position is changed
  • position: used for controlled components
  • onPress: returns an object with image url and index of image pressed
  • style: add custom styles

Autoplay Example

class SliderTests extends Component {
    constructor(props) {
        super(props);

        this.state = {
            position: 1,
            interval: null
        };
    }

    componentWillMount() {
        this.setState({interval: setInterval(() => {
            this.setState({position: this.state.position === 2 ? 0 : this.state.position + 1});
        }, 2000)});
    }

    componentWillUnmount() {
        clearInterval(this.state.interval);
    }

    render() {
        return (
            <View style={styles.container}>
                <ImageSlider
                    images={[
                        `http://placeimg.com/640/480/any`,
                        `http://placeimg.com/640/480/any`,
                        `http://placeimg.com/640/480/any`,
                    ]}
                    position={this.state.position}
                    onPositionChanged={position => this.setState({position})}/>
            </View>
        );
    }
}

To Do

Please feel free to fork and PR!

  • Add the option for custom buttons

License

MIT

FAQs

Package last updated on 21 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts