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

v2.0.0

Published

An invertible ScrollView for React Native

Downloads

2,648

Readme

InvertibleScrollView Slack

InvertibleScrollView is a React Native scroll view that can be inverted so that content is rendered starting from the bottom, and the user must scroll down to reveal more. This is a common design in chat applications and the command-line terminals. InvertibleScrollView also supports horizontal scroll views to present content from right to left.

It conforms to ScrollableMixin so you can compose it with other scrollable components.

npm package

Installation

Use this with react-native 0.8.0-rc or later.

npm install react-native-invertible-scroll-view

Usage

Compose InvertibleScrollView with the scrollable component you would like to invert. In the case of a ListView, you would write:

import React from 'react-native';
let {
  ListView,
  Text,
  TouchableHighlight,
  View,
  StyleSheet,
} = React;
import InvertibleScrollView from 'react-native-invertible-scroll-view';

class InvertedScrollComponent extends React.Component {
  constructor(props, context) {
    super(props, context);
    this._data = [];
    this.state = {
      dataSource: new ListView.DataSource({
        rowHasChanged: (r1, r2) => r1 !== r2,
      }),
    };
  }

  render() {
    return (
      <ListView
        renderScrollComponent={props => <InvertibleScrollView {...props} inverted />}
        dataSource={this.state.dataSource}
        renderHeader={this._renderHeader.bind(this)}
        renderRow={this._renderRow.bind(this)}
        style={styles.container}
      />
    );
  }

  _renderHeader() {
    return (
      <TouchableHighlight
        onPress={this._onPress.bind(this)}
        style={styles.button}>
        <Text>Add a row</Text>
      </TouchableHighlight>
    );
  }

  _renderRow(row) {
    return <Text key={row} style={styles.row}>{row}</Text>
  }

  _onPress() {
    this._data.push(`${new Date}`);
    var rows = this._data;
    // It's important to keep row IDs consistent to avoid extra rendering. You
    // may need to reverse the list of row IDs so the so that the inversion
    // will order the rows correctly.
    var rowIds = rows.map((row, index) => index).reverse();
    this.setState({
      dataSource: this.state.dataSource.cloneWithRows(rows, rowIds),
    });
  }
}

let styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  button: {
    padding: 20,
    borderStyle: 'solid',
    borderWidth: 1,
    borderColor: 'black',
  },
  row: {
    padding: 4,
  },
});

NOTE: When inverting a ListView, you must create a ListView that delegates to an InvertibleScrollView as shown above and not the other way around. Otherwise it will not be able to invert the rows and the content will look upside down. This is true for any scroll view that adds its own children, not just ListView.

Tips and Caveats

  • Horizontal scroll views are supported
  • To scroll to the bottom, call scrollTo(0) on a ref to the scroll view
  • When the scroll view is inverted, InvertibleScrollView wraps each child in a View that is flipped
  • Scroll views that add children (ex: ListViews) must delegate to InvertibleScrollViews so that the children can be properly inverted
  • List section headers are unsupported
  • Styles like padding are not corrected, so top padding will actually pad the bottom of the component
  • Properties like contentOffset and contentInset are not flipped; for example, the top inset adjusts the bottom of an inverted scroll view

Implementation

InvertibleScrollView uses a scale transformation to efficiently invert the view. The scroll view's viewport is inverted to flip the entire component, and then each child is inverted again so that the content appears unflipped.