npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-lazy-swiper

v1.0.3

Published

A swiper for React Native (0.26+) with lazy-loaded contents.

Downloads

16

Readme

React Native Lazy Swiper

A swiper for React Native (0.26+) with lazy-loaded contents. This component is currently support for iOS. It still runs on Android but without swipe feature.

Installation

npm install react-native-lazy-swiper --save

Usage

  • Define onSwipeEnd props: in this function, set nextIndex of component's state to currentIndex prop then pass the rerender callback function to setState method as second argument.
  • Define renderItem props: use this function to render each content for the swiper
  • [Optional] Define width for child views. Default width is screen width.
  • To swipe next manually: lazySwiper.swipeNext()
  • To swipe back manually: lazySwiper.swipeBack()
  • To go to specific item (no animation supported): set currentIndex of component's state to specific index.

Example:

[...]
import LazySwiper from 'react-native-lazy-swiper'

class App extends React.Component{
    constructor(props){
        super(props)
        this.state = {
            currentIndex: 0,
            data: []
        }
    }
    componentDidMount(){
        //Fetch data array
        fetch(...).done((result) => {
            this.setState({data: result})
        })
    }
    onSwipeEnd(nextIndex, rerender){
        this.setState({
            currentIndex: nextIndex
        }, rerender)
    }
    /**
     *  Bind this to previous button to manually swipe to the previous content.
     *  This should work on Android but without animation
     */
    prev(){
        this._lazySwiper.swipeBack()
    }
    /**
     *  Manually go to a specific content by reset new currentIndex to component's state
     */
    goTo(index){
        this.setState({
            currentIndex: index
        })
    }
    /**
     *  Bind this to next button to manually swipe to the next content.
     *  This should work on Android but without animation
     */
    next(){
        this._lazySwiper.swipeNext()
    }
    /**
     *  Render each content of the Swiper for each item in data array.
     */
    renderItem(item, index){
        return <View>
            <Text>No {index}: {item.name}</Text>
        </View>
    }
    render(){
        const {currentIndex, data} = this.state
        return <LazySwiper 
            ref={ (lazySwiper) => {this._lazySwiper = lazySwiper} }
            currentIndex={currentIndex}
            data={data}
            renderItem={(item, index) => this.renderItem(item, index)}
            onSwipeEnd={(nextIndex, rerender) => this.onSwipeEnd(nextIndex, rerender)}
        />
    }
}

Props

  • currentIndex: (number, isRequired) to set specific displayed content of the swiper.
  • data: (array, isRequired) list of items to show swiper contents.
  • renderItem: (function(item, index), isRequired) to render each swiper content. Parameters:
    • item: item of data array
    • index: index of the item in data array
  • onSwipeEnd: (function(nextIndex, rerender), isRequired) to set to new currentIndex and rerender the swiper. Define this will help the swiper render new content and swipe out unnessessary content. Parameters:
    • nextIndex: (number) set this to currentIndex of the state of the component which render the swiper.
    • rerender: (function()) pass this to setState method from above as second argument (sorry for this mysterious callback function but I found no other way).

LICENSE

MIT