GithubHelp home page GithubHelp logo

isabella232 / react-vscroll Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zendesk/react-vscroll

0.0 0.0 0.0 26 KB

Virtual Scrolling component for React that handles dynamic rows with unknown heights. eg. dynamic subtrees, Images, Iframes, etc.

License: Apache License 2.0

JavaScript 100.00%

react-vscroll's Introduction

React VScroll

A virtual scrolling container that supports dynamic child elements with heights that could change over time. ie. dynamic subtrees / images / iframes / etc.

In most other implementations of virtual scrolling, rows are assumed to contain static information that won't change over time. This is problematic because in a highly dynamic real time system, rows could contain large subtrees that may await for data prior to rendering. This prevents most virtual scrollers from accurately determining a row height on mount. The same issues apply for loading images and iframes, which involves asynchronous asset loading and subsequent height change.

This virtual scroller takes into account of heights changing over time, and is designed to react and correct scroll positions when row heights change. Implementation of fake rows is similar to other approaches where we use a top and bottom spacer and only renders rows within the viewport + some configurable allowance.

Installation

In NPM

npm install this package and

var vscroll = require('react-vscroll');

Usage

import { VContainer } from 'react-vscroll';

export default function Container() {
	return (
		<VContainer
			className={ 'a-container-class' }
			style={ { display: 'flex', flexDirection: 'column' } }
			items={ items }
			initialHeight={ 80 }
			scrollBottomThreshold={ 400 }
			stickBottom={ true }
			renderItem={ function(item){ return <div id={ item.id }>{ item.text }</div> } }
		/>
	)
}

Demo

  1. git clone this package and npm install.

  2. npm start. This will run the example here.

  3. Browse to http://localhost:5000

Configuration Options

Array items

Data for the list of items you want to virtual render.

Number initialHeight

The virtual scrolling algorithm works by assuming an initial height, then reactively applying height corrections over time.

Function renderItem

renderItem is passed args (item), where item is the value obtained from iterating items

Number scrollBottomThreshold

Number of pixels from the bottom of the scroller where stickBottom will no longer work. This is useful for cases where we want to prevent a chat log from auto scrolling to the bottom if the user is viewing a past message somewhere at the top of the chat log.

String className

Standard className prop used for JSX components

Object style

Standard style prop used for JSX components

Function renderIfNotBottom

Use this function for conditionally rendering a component if the scroller is not at the bottom. This is useful for rendering floating buttons like "Scroll to bottom".

Bool stickBottom

Determines whether the chat log will attempt to stick to the bottom on mount / update. This is mostly useful for chat logs where the user is viewing chat messages from bottom to top.

Function containerDidMount

This allows you to specify hooks to run when the virtual scroller has been mounted.

Function containerWillUnmount

This allows you to specify hooks to run when the virtual scroller has been unmounted.

Number allowance

Controls the number of rows that are rendered outside the viewport.

Contributing

Improvements are always welcome. Please follow these steps to contribute

  1. For proposed changes, please create a pull request

  2. For bugs and feature requests, please create an issue

License

Use of this software is subject to important terms and conditions as set forth in the LICENSE file

react-vscroll's People

Contributors

geekyme avatar zillding avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.