Socket
Socket
Sign inDemoInstall

react-inverted-scrollview

Package Overview
Dependencies
6
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-inverted-scrollview

Easily support inverted scrolling. Maintains a correct scroll position when new content is added.


Version published
Weekly downloads
401
increased by24.92%
Maintainers
1
Install size
14.1 kB
Created
Weekly downloads
 

Readme

Source

Build Status

React Inverted ScrollView

Easily support inverted scrolling in for example chat apps. Maintains a correct scroll position when new content is added.

Installation:

npm install react-inverted-scrollview --save

Example:

import _ from 'lodash';
import React, { Component } from 'react';
import ScrollView from 'react-inverted-scrollview';

class MyComponent extends Component {
    state = {
        messages: _.range(30).map(index => ({
            id: index,
            text: `message-${index}`
        }))
    };

    scrollToBottom() {
        if (!this.scrollView) return;
        this.scrollView.scrollToBottom();
    }

    scrollToTop() {
        if (!this.scrollView) return;
        this.scrollView.scrollToTop();
    }

    handleScroll = ({ scrollTop, scrollBottom }) => {
        console.log('scrollTop', scrollTop);
        console.log('scrollBottom', scrollBottom);
    };

    render() {
        const { messages } = this.state;
        return (
            <ScrollView
                width={400}
                height={400}
                ref={ref => (this.scrollView = ref)}
                onScroll={this.handleScroll}
            >
                {messages.map(message => <div key={message.id}>{message.text}</div>)}
            </ScrollView>
        );
    }
}

API

Props

PropTypeDefault
widthnumber100
heightnumber100
onScroll(info: { scrollBottom: number, scrollTop: number }) => any() => {}
styleObject {}{}
restoreScrollPositionOnUpdatebooleantrue
childrenReact.Node or ({restoreScrollPosition}) => NodeNode

Instance methods

instance.scrollToBottom();
instance.scrollToTop();
instance.setScrollBottom(value);
instance.setScrollTop(value);
instance.restoreScrollPosition();

Check out the examples:

git clone https://github.com/vejersele/react-inverted-scrollview.git
cd react-inverted-scrollview
npm install
npm run storybook

Keywords

FAQs

Last updated on 04 Jul 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc