1.0.6 • Published 6 years ago

react-native-masonry-layout v1.0.6

Weekly downloads
398
License
MIT
Repository
github
Last release
6 years ago

react-native-masonry-layout

An easy to use, pure JS react-native component to render a masonry layout for any item view

中文文档

features

  • Full custom item view, Including style definition
  • Instead of adding a item per column, the optimal arrangement is automatically determined by the algorithm. Avoid the high gap in each column

preview

Usage

1.Install

npm

$ npm install --save react-native-masonry-layout

yarn

$ yarn add react-native-masonry-layout

2.Import

import Masonry from 'react-native-masonry-layout';

3.Render

<Masonry
  ref="masonry"
  columns={3} // optional - Default: 2
  renderItem={(item)=><View>
    <Text>some text</Text>
  </View>}
/>

Component Props

PropsTypeDescriptionDefault
columnsnumberDesired number of columns2
headerViewAdd view in front of the masonry layoutnull
footerViewAdd view in behind the masonry layoutnull
containerStyleViewStyleDefining the style of the container viewnull
renderItemfuncThe method used to render each itemnull
keyExtractorfuncBy default, the list looks for a key prop on each item and uses that for the React key. Alternatively, you can provide a custom keyExtractor prop.null

Other attributes are the same as ScrollView

Component Methods

addItems

Add Items to the Masonry component。The items height will be automatically calculated, and the item will be rendered one by one, and addItemsWithHeight should be used if it needs to be rendered in bulk

this.refs.masonry.addItems([
	{ key:1, text:"text1" },
	{ key:1, text:"text1" }
]);

addItemsWithHeight

Add items to masonry. Item height will be automatically calculated, but height attribute must be added to every item object data. This attribute is not the actual item rendering height, but a reference value for item assignment algorithm. Unlike addItems, items is rendered in bulk.

this.refs.masonry.addItems([
	{ key:1, text:"text1", height: 210 },
	{ key:1, text:"text1", height: 150 }
]);

clear

Clear the items of masonry.

this.refs.masonry.clear();
1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago