Giter VIP home page Giter VIP logo

react-native-masonry-list's Introduction

react-native-masonry-list

Pinterest like listview made in React Native. It just behaves like the FlatList so it is easy to use.

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

Installation

yarn add @react-native-seoul/masonry-list
import MasonryList from '@react-native-seoul/masonry-list';

For deno user (Experimental)

import RNMasonryList from "https://deno.land/x/react_native_masonry_list/index.ts";

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>;
keyPrefix?: string;
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;

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

keyPrefix - Add prefix for keying child views. This is currently incremented by 1.

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, index): string => index.toString()}
  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/react-native-masonry-list.git
    
  2. Navigate to example project

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

LICENSE

FOSSA Status

react-native-masonry-list's People

Contributors

ahmethalac avatar hanpanpan200 avatar hyochan avatar nathansbird avatar samzmann avatar vadko 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.