Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

reanimated-masonry-list

hyochan812MIT1.0.1TypeScript support: included

Reanimated2 Masonry List for Pinterest like UI implemented just like the [FlatList].

masonry, react-native, masonry-list, pinterest, flatlist, reanimated2

readme

reanimated-masonry-list

Pinterest like ScrollView made in React Native and Reanmated v2. It just behaves like the FlatList so it is easy to use. The package has been inherited by hyochan/react-native-masonry-list by the issue opened in hyochan/react-native-masonry-list/issues/14.

Npm Version Downloads CI codecov code style: prettier LICENSE PRs Welcome supports iOS supports Android supports web runs with expo

Installation

yarn add reanimated-masonry-list react-native-gesture-handler react-native-reanimated
import MasonryList from 'reanimated-masonry-list';

Preview

2-columns 3-columns 4-columns

You can use as many columns as you want. It is flexible!

YouTube

See how to use it

Blog

How it is made

Description

Current MasonryList extends ScrollView and can pass down its props. Indeed, this looks similar to FlatList to provide good developer experience. Look how this is used and compare to the FlatList.

The FlatList won't offer you to draw MansonryList because when you provide numColumns bigger than 1, the native view will switch to FlatList to GridView which will render its children with identical height only.

Our MasonryList view component is able to render all child views with all different sizes.

Props

innerRef?: MutableRefObject<ScrollView | undefined>;
loading?: boolean;
refreshing?: RefreshControlProps['refreshing'];
onRefresh?: RefreshControlProps['onRefresh'];
onEndReached?: () => void;
onEndReachedThreshold?: number;
style?: StyleProp<ScrollViewProps>;
data: T[];
renderItem: ({item: T, i: number}) => ReactElement;
LoadingView?: React.ComponentType<any> | React.ReactElement | null;
ListHeaderComponent?: React.ComponentType<any> | React.ReactElement | null;
ListEmptyComponent?: React.ComponentType<any> | React.ReactElement | null;
ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null;
numColumns?: number;
keyExtractor?: ((item: T | any, index: number) => string) | undefined;

innerRef - Expose ScrollView instance with ref, example usage: ref.current.scrollTo.

loading - Currently in loading status.

refreshing - Currently in refreshing status.

onRefresh - Callback when refresh has been triggered.

onEndReached - Callback when end is reached just like the onEndReached in FlatList

style - Style props for ScrollView which is the container view.

data - The array of the data for the view to render in renderItem

renderItem - Render custom view with the data passed down.

LoadingView - Custom loading view when the view is in loading status.

ListHeaderComponent - Header component

ListFooterComponent - Footer component

ListEmptyComponent - Component to render when the data is empty.

numColumns - Number of columns you want to render. Default to 2.

Usage

<MasonryList
  data={filteredItems}
  keyExtractor={(item): string => item.id}
  numColumns={2}
  showsVerticalScrollIndicator={false}
  renderItem={({item}) => <CardItem />}
  refreshing={isLoadingNext}
  onRefresh={() => refetch({first: ITEM_CNT})}
  onEndReachedThreshold={0.1}
  onEndReached={() => loadNext(ITEM_CNT)}
/>

Run Example

  1. Clone the repository.

     git clone https://github.com/hyochan/reanimated-masonry-list.git
  2. Navigate to example project

     cd RNMasonryExample
  3. Install packages and run it as you do in react-native project.

LICENSE

MIT

changelog

1.2.1

  • Fix keyExtractor types.

1.2.0

What's Changed

  • Remove keyPrefix and replace with keyExtractor like [FlatList].

1.1.5

What's Changed

1.1.4

Small internal lint fixes.

1.1.3

Layout styling fixes #23

  • Added ListComponentStyleProp to provide header styles
  • Moved style prop from scrollview to view that wraps items in list
  • Added contentContainerStyle prop
  • Renamed prop for ScrollView from style to containerStyle

1.1.1

Expose innerRef to use ref of MasonryList #21

1.1.0

Fix element typings and add default flex: 1 style

Update packages and make it a pure component

1.0.9

Fix element typings and add default flex: 1 style

1.0.8

Add support for horizontal layout #17

1.0.7

Use refreshing from props if specified #13

1.0.6

Fix unpublished typings

1.0.1

Initial release