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

redux-first-router-scroll-container-native

v1.1.1

Published

scroll restoration for React Native using Redux First Router

Downloads

16

Readme

redux-first-router-scroll-container-native

A straightforward scroll restoration component for React Native using Redux First Router

Installation

yarn add redux-first-router-scroll-container-native

Usage

import React from 'react'
import { connect } from 'react-redux'
import { FlatList, TouchableOpacity } from 'react-native'
import { back } from 'redux-first-router'
import ScrollContainer from 'redux-first-router-scroll-container-native'

export default ({ scene, dispatch }) =>
  scene === 'SCENE1'
    ? <ScrollContainer
        component={FlatList}// FlatList, ScrollView, SectionList, ListView, etc
        scrollKey='scene-1' // used to differentiate between multiple scrollViews
        forceRestore={0}    // increment to force restoration after asynchrony
      >
        <TouchableOpacity onPress={() => dispatch({ type: 'SCENE2' })} />
      </ScrollContainer>
    : <ScrollContainer 
        component={ScrollView} // ScrollView is default by the way, no need to pass it
        scrollKey='scene-2'
      >
        <TouchableOpacity onPress={back} />
      </ScrollContainer>

const mapState = ({ location }) => ({
  scene: location.type
})

export default connect(mapState)(MyComponent)

Pros

  • no HOCs are needed
  • both y and x values can be restored
  • no additional <Provider /> components are needed (it's redux-powered)
  • scroll position recorded in both onMomentumScrollEnd and onScrollEndDrag
  • even if you don't use the back/next methods from redux-first-router, and you navigate to a route you were just at, it will be determined you are revisiting a page worth of a nifty scroll restoration. Hurray!
  • increment forceRestore or call ref.restoreScroll() after asynchronous events update the page with more data and a longer/wider page. Won't be needed if you are using things like redux-persist--that way when you return to the page you already have the data you needed and it renders in its full dimensions on mount :)
  • will handle the case where you render a ScrollContainer in the exact same place within the component tree and React re-uses it and doesn't remount it. In that case, instead of componentDidMount handling scroll restoration, componentDidUpdate handles scroll restoration. Long live React! If you want to force mounting a new component, simply give it a unique key prop.

Contributing

We use commitizen, so run npm run commit to make commits. A command-line form will appear, requiring you answer a few questions to automatically produce a nicely formatted commit. Releases, semantic version numbers, tags and changelogs will automatically be generated based on these commits thanks to semantic-release. Be good.