1.11.2 • Published 2 years ago

react-native-autoscroll-flatlist v1.11.2

Weekly downloads
152
License
MIT
Repository
github
Last release
2 years ago

react-native-autoscroll-flatlist

react-native-autoscroll-flatlist is released under the MIT license. react-native-autoscroll-flatlist's current npm package version

An enhanced version of the original react-native <FlatList> component with built-in support for both Javascript and Typescript usage.

This component enables auto-scrolling on new item added to the list - which works like any chat client.

Now supports horizontal <FlatList> as well in version >= 1.6.0.

Demo

demo

Features

Auto-scroll is disabled when scrolled away from end of list. There are 3 ways to re-enable auto-scrolling:

  • You can manually scroll back to the end of list.

scroll to end manually

  • You can tap on the scrollToEndIndicator (customizable) shown on the bottom right of the list.

scroll to end by tapping on scrollToEndIndicator

  • You can tap on the newMessageAlertComponent (customizable) shown on the top of the list.

scroll to end by tapping on newMessageAlert

  • Inverted FlatList is also supported by passing the boolean inverted to the props.

inverted support

  • Horizontal (landscape) orientation is supported by passing the boolean horizontal to the props.

horizontal support

horizontal-inverted support

Installation

npm install --save react-native-autoscroll-flatlist

or

yarn add react-native-autoscroll-flatlist

Example Usage

Import the component with:

import {AutoScrollFlatList} from "react-native-autoscroll-flatlist";

and simply use it like an ordinary <FlatList>, for example:

<AutoScrollFlatList
    ref={this.myRef}
    threshold={20}
    data={myData}
    renderItem={({item, index}) => <YourComponent item={item} index={index} />}
    keyExtractor={item => item.id}
/>

You can check out the example folder for further details.

You can check out App.tsx, or replace it with the content of App-Horizontal.tsx to try out usage in landscape orientation.

Note that the landscape demo does not work in react-native-web because of the constraint with ScreenOrientation not being able to lock it to horizontal.

Properties

This component extends the official FlatListProps with the following additional props:

You can read the type definitions file for more details and explanations.

Methods

This component extends the official FlatList Methods with the following modified / additional methods:

MethodParametersDescription
scrollToEndparams: {animated: boolean} = {animated: true}Set newItemCount to 0 and then trigger scrollToOffset to end of page.
isAutoScrollingReturns whether auto-scrolling (boolean) is in effect.

FAQ for usage on react-native-web

There are certain caveats for usage on react-native-web:

Q: My page keeps expanding in height and the autoscroll function is not being triggered. How do I fix this?

A: For usage in react-native, usually add a flex property such as flex: 1 to the container would be sufficient to get FlatList working. However, when it comes to react-native-web, you will have to explicitly set the height of the container such that it will not keep expanding. To do so, a simple fix would be to add

height: Dimensions.get("window").height
maxHeight: Dimensions.get("window").height

to the container style (depending on your use cases).

1.11.2

2 years ago

1.11.1

2 years ago

1.11.0

3 years ago

1.10.3

3 years ago

1.10.2

3 years ago

1.10.1

3 years ago

1.10.0

3 years ago

1.9.3

4 years ago

1.9.2

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.2

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.5

4 years ago

1.7.4

4 years ago

1.7.3

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago