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-paged-scroll-view

v2.0.4

Published

A higher-order React Native component to compute the current and total pages of a ScrollView

Downloads

51

Readme

react-native-paged-scroll-view

npm version

A higher-order React Native component to compute the current and total pages of a ScrollView-compatible component

Note: I've tried and will try to keep this mostly functional and current, but my job no longer involves working with React Native, so it's a little tough to really dig in and get to the bottom of tricky issues. I'll try to maintain this, but I won't be actively improving it. I'll gladly accept PRs though!

Introduction

This module implements a higher-order component that computes the current and total pages contained in a React Native ScrollView (or functionally similar) component. So it's really very simple. Seriously, when you get down to it it's like a division and a floor function. But it attempts to solve layout race conditions, re-layout and other subtleties. This component could trivially be used as a swiper alongside a page indicator but does not implement that itself.

To be clear, this is strictly just a page-computing component. I assume you'll use it with pagingEnabled={true}, and it doesn't add paged scrolling for Android.

Example

PagedScrollViewExample

import { ScrollView } from 'react-native'
import AddPaging from 'react-native-paged-scroll-view'
var PagedScrollView = AddPaging(ScrollView)

  ...
  handlePageChange (state) {
    console.log('current horizontal page:', state.currentHorizontalPage)
    console.log('current vertical page:  ', state.currentVerticalPage)
    console.log('total horizontal pages: ', state.totalHorizontalPages)
    console.log('total vertical pages:   ', state.totalVerticalPages)
  }

  render () {
    return (
      <PagedScrollView onPageChange={this.handlePageChange.bind(this)}>
        ...
      </PagedScrollView>
    )
  }
  ...

Installation

$ npm install react-native-paged-scroll-view

Usage

require('react-native-paged-scroll-view')(Component, [scrollViewRefPropName="ref"])

Wrap either a ScrollView or a component functionally equivalent (implements onScroll and similar basic methods). Returns a higher order component with props passed through.

Arguments:

  • Component: The component being wrapped. It must implement the basic methods of a ScrollView.
  • scrollViewRefPropName: the name of the property passed to Component that will return the ref. This exists in case you're using a wrapped a ScrollView component for which ref returns the ref of the wrapper instead of the ref of the ScrollView. If you provide this property, then your wrapped ScrollView should have a property ref={this.props.<scrollViewRefPropName>} with your method name inserted. If you're just using a ScrollView though, you should be fine. Suggestions on how to improve this are welcome.

Props:

  • onPageChange: function(state): Executed on initial layout, when the page changes, or when the inner content changes. Callback is passed state object containing:
    • totalHorizontalPages: total number of horizontal pages, rounded to the nearest integer.
    • totalVerticalPages: total number of vertical pages, rounded to the nearest integer.
    • currentHorizontalPage: the current horizontal page, rounded to the nearest integer.
    • currentVerticalPage: the current vertical page, rounded to the nearest integer.
  • onInitialization: function(ref): Executed once, when the component is initially mounted and only once the dimensions have been measured. Useful, for example, for scrolling to a specific page once the component is mounted.

Attributes:

  • ref.scrollX: current horizontal scroll offset
  • ref.scrollY: current vertical scroll offset
  • ref.state.currentHorizontalPage: as defined above
  • ref.state.currentVerticalPage: as defined above
  • ref.state.totalHorizontalPages: as defined above
  • ref.state.totalVerticalPages: as defined above

Methods:

  • ref.scrollToPage(horizontal, vertical, animated): Scroll to a specific page

License

(c) 2015 Ricky Reusser. MIT License.