pagescrollview
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

pagescrollview

PRs Welcome TypeScript npm npm

React Native ScrollView component interface that fills all the available area and has a working scrolling (!).

It fixes some very common issues with ScrollView: 1, 2, 3, 4

2.0.0! - 2022-06-17

It now uses a FlatList instead of the ScrollView under the hoods, as FlatLists/SectionLists aren't allowed inside a ScrollView. This doesn't change other behaviors or performance.

It also includes those commonly used props as default:

Compatible with Web and Expo.

💿 Installation

npm install pagescrollview
# or
yarn add pagescrollview

📖 Usage

The usage is exactly how you would use the ScrollView, with the few extra optional props listed in the Type section below, without having to deal with the said bugs above! This example is just to have something pretty in this readme!

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { PageScrollView } from 'pagescrollview'

const items = 20;

export default () => {
  return (
    <PageScrollView backgroundColor='#ebf3f3' style={styles.style}>
      {[...Array(items)].map((_,i) => {
        const backgroundColor = `hsl(${Math.floor((360/items)*i)}, 90%, 62%)`
        return (<View key={i} style={[styles.itemView, { backgroundColor }]}>
          <Text style={styles.itemText}>{`${i+1}/${items}`}</Text>
        </View>)
      })}
    </PageScrollView>
  );
}

const styles = StyleSheet.create({
  style: {
    padding: 10,
  },
  itemView: {
    width: '100%',
    margin: 5,
    padding: 40,
  },
  itemText: {
    textAlign: 'center',
    fontSize: 20,
    fontWeight: 'bold'
  }
});

🍟 Snack of the code above

Type

export type PageScrollViewProps = Omit<FlatListProps,
  'ListFooterComponentStyle' | 'ListFooterComponent' | 'data' | 'renderItem' | 'keyExtractor'
> & {
  /** Use this to change the backgroundColor. Internally, it changes FlatList's `style` and `ListFooterComponentStyle`.
   *
   * We change `style` to have backgroundColor when iOS users overscroll with `bounces`. */
  backgroundColor?: string;
};

📰 Changelog

Package Sidebar

Install

npm i pagescrollview

Weekly Downloads

2

Version

2.2.0

License

MIT

Unpacked Size

9.02 kB

Total Files

5

Last publish

Collaborators

  • srbrahma