0.6.0 • Published 7 years ago

react-scroll-view v0.6.0

Weekly downloads
49
License
-
Repository
-
Last release
7 years ago

React Scroll View

A more sane way to work with scrolling inside React. The basis idea is to wrap elements which should be able to scroll inside a createScrollContainer function and then wrap elements which should interact with the scroll container inside a withScrollApi function, which will then add the scroll API to it's props.

If for instance we have a parent.js

import React from 'react';
import { createScrollContainer } from 'react-scroll-view';

export default createScrollContainer()(({ children }) => (
  <div>
    {children}
  </div>
));

it's children would then be able to interact with it using this.props.scroll

import React, { Component } from 'react';
import { withScrollApi } from 'react-scroll-view';

export default withScrollApi(class Child extends Component {
  constructor() {
    this.state = {
      atEnd: false;
      items: new Array(500).fill(undefined);
    }
  }
  componentDidMount() {
    const { scroll } = this.props;
    scroll.addEventListener('onend', () => {
      this.setState({
        atEnd: true,
      })
    });
  }
  render() {
    return (
      <div>
        {this.state.items.map(() => <div>{this.state.etEnd ? 'true' : 'false' }</div>)}
      </div>
    )
  }
});
0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.7

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago