Code Monkey home page Code Monkey logo

react-native-super-grid's Introduction

React Native Super Grid

npm version npm download

Responsive Grid View for React Native.

Getting Started

This library export two components - FlatGrid (similar to FlatList) and SectionGrid (similar to SectionList). Both components render a Grid layout that adapts itself to various screen resolutions.

Instead of passing an itemPerRow argument, you pass itemDimension and each item will be rendered with a dimension size equal to or more than (to fill the screen) the given dimension.

Internally, these components use the native FlatList and SectionList.

Demo Snack

Version 3.x, please refer v3 branch for documentation

Version 2.x and older, please refer v2 branch for documentation

Versions

  • Use version 6.0.0 for RN 0.74.0 and above
  • Use version 5.1.0 for older versions of RN

Installing

You can install the package via npm.

npm install react-native-super-grid

Usage (FlatGrid)

import { FlatGrid } from 'react-native-super-grid';
<FlatGrid
  itemDimension={130}
  data={[1,2,3,4,5,6]}
  renderItem={({ item }) => (<Text>{item}</Text>)}
/>

Usage (SimpleGrid)

This component is similar to the FlatGrid but does not use a FlatList, instead, it simply maps over the data items. This is useful if you need to put a grid inside a ScrollView or if you have a small array.

import { SimpleGrid } from 'react-native-super-grid';
<SimpleGrid
  itemDimension={130}
  data={[1,2,3,4,5,6]}
  renderItem={({ item }) => (<Text>{item}</Text>)}
/>

Usage (SectionGrid)

import { SectionGrid } from 'react-native-super-grid';
<SectionGrid
  itemDimension={130}
  sections={[
    {
      title: 'Numbers',
      data: [1,2,3,4,5,6],
    },
    {
      title: 'Alphabets',
      data: ['A', 'B', 'C', 'D', 'E'],
    },
  ]}
  renderItem={({ item }) => (<Text>{item}</Text>)}
  renderSectionHeader={({ section }) => (
    <Text style={{ fontSize: 20 }}>{section.title}</Text>
  )}
/>

Properties

Property Type Default Value Description
renderItem Function Function to render each object. Should return a react native component. Same signature as that of FlatList/SectionList's renderItem (with an additional key rowIndex).
data (for FlatGrid) sections (for SectionGrid) Array Data to be rendered. renderItem will be called with each item in this array. Same signature as that of FlatList/SectionList.
itemDimension Number 120 Minimum width or height for each item in pixels (virtual).
fixed Boolean false If true, the exact itemDimension will be used and won't be adjusted to fit the screen.
spacing Number 10 Spacing between each item.
style FlatList styles (Object) Styles for the container. Styles for an item should be applied inside renderItem. Note: If you set adjustGridToStyles to true then padding added in this prop will be used to adjust the total dimensions of the grid to reflect the padding in this style object.
additionalRowStyle styles (Object) Additional styles for rows (rows render multiple items within), apart from the generated ones.
itemContainerStyle styles (Object) Style for item's container. Not needed for most cases.
staticDimension Number Specifies a static width or height for the container. If not passed, maxDimension will be used.
maxDimension Number Specifies a maximum width or height for the container. If not passed, full width/height of the screen will be used. Note: If you set adjustGridToStyles to true then you can alternatively use the contentContainerStyle prop and set maxWidth or maxHeight.
horizontal boolean false If true, the grid will be scrolling horizontally. If you want your item to fill the height when using a horizontal grid, you should give it a height of '100%'. This prop doesn't affect the SectionGrid, which only scrolls vertically.
onLayout Function Optional callback ran by the internal FlatList or SectionList's onLayout function, thus invoked on mount and layout changes.
listKey String A unique identifier for the Grid. This key is necessary if you are nesting multiple FlatGrid/SectionGrid inside another Grid (or any VirtualizedList).
keyExtractor Function A function (item, rowItemIndex) => {String} that should return a unique key for the item passed.
invertedRow boolean Reverses the direction of row items. It can be used with the inverted property.
maxItemsPerRow number Specifies the maximum number of items to render per row
contentContainerStyle styles (Object) This is the regular FlatList/SectionList prop. If you set adjustGridToStyles to true and specify maxWidth or maxHeight it will be used the same as maxDimension. In addition, padding added here will be used to adjust the total dimensions of the grid to reflect the padding in this style object.
adjustGridToStyles boolean Set to true when you want the library to automatically adjust the total dimensions of the grid based on style and contentContainerStyle props
customFlatList (for FlatGrid) ElementType Replaces FlatList in FlatGrid with ElementType. E.g. Animated.FlatList
customSectionList (for SectionGrid) ElementType Replaces SectionList in SectionGrid with ElementType. E.g. Animated.SectionList
onItemsPerRowChange Function A callback (itemsPerRow: number) => void that is called when number of items per row is determined.

All additional props you pass will be passed on to the internal FlatList/SectionList. This means you can make use of various props and methods like ListHeaderComponent, onEndReached, onRefresh...etc. While these are not tested for compatibility, most of them should work as expected.

In SectionGrid, section argument in methods like renderSectionHeader, renderSectionFooter, ItemSeparatorComponent will slightly different from the actual section you passed. The data key in the section will be the grouped versions of items (items that go in one row), and the original list of items can be found in originalData key. All other keys will remain intact.

Full width items

To make an item full width, simply include _fullWidth: true in the data object for that item. For example:

{ name: 'TURQUOISE', code: '#1abc9c', _fullWidth: true }

FlatGrid Example

import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { FlatGrid } from 'react-native-super-grid';

export default function Example() {
  const [items, setItems] = React.useState([
    { name: 'TURQUOISE', code: '#1abc9c' },
    { name: 'EMERALD', code: '#2ecc71' },
    { name: 'PETER RIVER', code: '#3498db' },
    { name: 'AMETHYST', code: '#9b59b6' },
    { name: 'WET ASPHALT', code: '#34495e' },
    { name: 'GREEN SEA', code: '#16a085' },
    { name: 'NEPHRITIS', code: '#27ae60' },
    { name: 'BELIZE HOLE', code: '#2980b9' },
    { name: 'WISTERIA', code: '#8e44ad' },
    { name: 'MIDNIGHT BLUE', code: '#2c3e50' },
    { name: 'SUN FLOWER', code: '#f1c40f' },
    { name: 'CARROT', code: '#e67e22' },
    { name: 'ALIZARIN', code: '#e74c3c' },
    { name: 'CLOUDS', code: '#ecf0f1' },
    { name: 'CONCRETE', code: '#95a5a6' },
    { name: 'ORANGE', code: '#f39c12' },
    { name: 'PUMPKIN', code: '#d35400' },
    { name: 'POMEGRANATE', code: '#c0392b' },
    { name: 'SILVER', code: '#bdc3c7' },
    { name: 'ASBESTOS', code: '#7f8c8d' },
  ]);

  return (
    <FlatGrid
      itemDimension={130}
      data={items}
      style={styles.gridView}
      // staticDimension={300}
      // fixed
      spacing={10}
      renderItem={({ item }) => (
        <View style={[styles.itemContainer, { backgroundColor: item.code }]}>
          <Text style={styles.itemName}>{item.name}</Text>
          <Text style={styles.itemCode}>{item.code}</Text>
        </View>
      )}
    />
  );
}

const styles = StyleSheet.create({
  gridView: {
    marginTop: 10,
    flex: 1,
  },
  itemContainer: {
    justifyContent: 'flex-end',
    borderRadius: 5,
    padding: 10,
    height: 150,
  },
  itemName: {
    fontSize: 16,
    color: '#fff',
    fontWeight: '600',
  },
  itemCode: {
    fontWeight: '600',
    fontSize: 12,
    color: '#fff',
  },
});
iPhone6 Portrait iPhone6 Landscape
iPhone6 Portrait iPhone6 Landscape
iPad Air 2 Portrait iPad Air 2 Landscape
iPad Air 2 Portrait iPad Air 2 Landscape
Android Portrait Android Landscape
Android Portrait Android Landscape
Android Horizontal Portrait Android Horizontal Landscape
Android Horizontal Portrait Android Horizontal Landscape
iPhone Horizontal Portrait iPhone Horizontal Landscape
iPhone Horizontal Portrait iPhone Horizontal Landscape

SectionGrid Example

import React, { Component } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { SectionGrid } from 'react-native-super-grid';

export default function Example() {
  const [items, setItems] = React.useState([
    { name: 'TURQUOISE', code: '#1abc9c' },
    { name: 'EMERALD', code: '#2ecc71' },
    { name: 'PETER RIVER', code: '#3498db' },
    { name: 'AMETHYST', code: '#9b59b6' },
    { name: 'WET ASPHALT', code: '#34495e' },
    { name: 'GREEN SEA', code: '#16a085' },
    { name: 'NEPHRITIS', code: '#27ae60' },
    { name: 'BELIZE HOLE', code: '#2980b9' },
    { name: 'WISTERIA', code: '#8e44ad' },
    { name: 'MIDNIGHT BLUE', code: '#2c3e50' },
    { name: 'SUN FLOWER', code: '#f1c40f' },
    { name: 'CARROT', code: '#e67e22' },
    { name: 'ALIZARIN', code: '#e74c3c' },
    { name: 'CLOUDS', code: '#ecf0f1' },
    { name: 'CONCRETE', code: '#95a5a6' },
    { name: 'ORANGE', code: '#f39c12' },
    { name: 'PUMPKIN', code: '#d35400' },
    { name: 'POMEGRANATE', code: '#c0392b' },
    { name: 'SILVER', code: '#bdc3c7' },
    { name: 'ASBESTOS', code: '#7f8c8d' },
  ]);

  return (
    <SectionGrid
      itemDimension={90}
      // staticDimension={300}
      // fixed
      // spacing={20}
      sections={[
        {
          title: 'Title1',
          data: items.slice(0, 6),
        },
        {
          title: 'Title2',
          data: items.slice(6, 12),
        },
        {
          title: 'Title3',
          data: items.slice(12, 20),
        },
      ]}
      style={styles.gridView}
      renderItem={({ item, section, index }) => (
        <View style={[styles.itemContainer, { backgroundColor: item.code }]}>
          <Text style={styles.itemName}>{item.name}</Text>
          <Text style={styles.itemCode}>{item.code}</Text>
        </View>
      )}
      renderSectionHeader={({ section }) => (
        <Text style={styles.sectionHeader}>{section.title}</Text>
      )}
    />
  );
}

const styles = StyleSheet.create({
  gridView: {
    marginTop: 20,
    flex: 1,
  },
  itemContainer: {
    justifyContent: 'flex-end',
    borderRadius: 5,
    padding: 10,
    height: 150,
  },
  itemName: {
    fontSize: 16,
    color: '#fff',
    fontWeight: '600',
  },
  itemCode: {
    fontWeight: '600',
    fontSize: 12,
    color: '#fff',
  },
  sectionHeader: {
    flex: 1,
    fontSize: 15,
    fontWeight: '600',
    alignItems: 'center',
    backgroundColor: '#636e72',
    color: 'white',
    padding: 10,
  },
});
iPhone SectionGrid Portrait iPhone6 Landscape
iPhone SectionGrid Portrait iPhone6 Landscape

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Changelog

[6.0.0] - 2024-06-12

  • Remove proptypes; Support for react native version 0.74.0 @saleel

[5.1.0] - 2024-03-28

  • Add support for fullWidth items @devjeff

[5.0.1] - 2024-03-23

  • Add readonly to types @annepham25

[5.0.0] - 2022-11-28

  • Add SimpleGrid component @paulrostorp

[4.6.0] - 2022-09-12

  • Add onItemsPerRowChange @wjaykim

[4.5.1] - 2022-09-08

  • Fix SectionGrid renderItem types @wjaykim

[4.5.0] - 2022-08-23

  • Add ability to add custom interfaces @Ryanjso

[4.4.3] - 2022-08-03

  • Update type defs to handle ref attribute @leezumstein

[4.4.2] - 2022-07-06

  • Fix itemIndex in keyExtractor

[4.4.1] - 2022-07-06

  • Fix SectionGrid types (title) @LightenedLimited

[4.4.0] - 2022-04-30

  • Introduce adjustGridToStyles prop @levic92

[4.3.0] - 2022-04-23

  • Add maxItemsPerRow option @levic92

[4.2.0] - 2021-05-27

  • Add invertedRow option @JeffGuKang

[4.1.2] - 2021-05-27

  • Fix prop-type for styles @siarheipashkevich

[4.1.1] - 2021-02-03

  • Update type definition @henrymoulton

[4.1.0] - 2021-01-16

  • Add additionalRowStyle prop @sanghavan

[4.0.3] - 2020-07-14

  • Remove ViewPropTypes @miracle2k

[4.0.2] - 2020-06-05

  • Fix type definition of v4 FlatList

[4.0.1] - 2020-06-05

  • Remove accidental console.log @ianmartorell

[4.0.0] - 2020-05-23

  • Improve SectionList performance by using hooks @IsaaX
  • Improve FlatList performance by using hooks
  • Add maxDimension prop @ianmartorell

[3.2.0] - 2020-04-03

  • Add keyExtractor prop @sammarks

[3.1.2] - 2019-09-27

  • Security updates in packages @dependabot

[3.1.1] - 2019-09-27

  • Fix type definitions @JulienKode

[3.1.0] - 2019-09-16

  • Support overriding of renderItem in SectionList @paldepind

[3.0.9] - 2019-08-16

  • Improve type definitions @Grohden

[3.0.8] - 2019-07-16

  • Fix type definitions @Grohden

[3.0.7] - 2019-06-29

  • Add listKey prop @josemiguelo

[3.0.6] - 2019-05-18

  • Fix type definitions @zhigang1992

[3.0.5] - 2019-05-04

  • Fix type definitions @zhigang1992

[3.0.4] - 2019-04-16

  • Fix type definitions @hisankaran

[3.0.3] - 2019-02-25

  • Fix type definitions @jgbernalp

[3.0.2] - 2019-02-20

  • Fix calculation bug where itemsPerRow became zero (#81).

[3.0.1] - 2019-02-02

  • Fix in section key passed to various SectionGrid props.

[3.0.0] - 2019-01-20

  • Rename components, FlatList renderItem signature, Performance improvements.

[2.4.3] - 2018-07-22

  • Fix deep copying issue in SectionGrid @andersonaddo

[2.4.2] - 2018-07-21

  • Add itemContainerStyle prop @KseniaSecurity

[2.4.1] - 2018-07-07

  • Add onLayout prop @ataillefer

[2.4] - 2018-05-11

  • renderItem index fix @andersonaddo

[2.3.2] - 2018-05-23

  • Typescript support for SuperGridSectionList @Anccerson

[2.3.0] - 2018-03-17

Added

  • Add SuperGridSectionList @andersonaddo

[2.1.0] - 2018-03-17

Added

  • Use FlatList instead of ListView
  • Fix spacing issues

[2.0.2] - 2018-01-11

Added

  • Allow dynamic update of itemDimension

[2.0.1] - 2017-12-13

Added

  • Fixed render empty section headers Warning. @mannycolon

[2.0.0] - 2017-12-02

Added

  • Add ability to have a horizontal grid. @Sh3rawi

[1.1.0] - 2017-11-03 (Target React Native 0.49+)

Added

  • Replace view.propTypes to ViewPropTypes for 0.49+. @caudaganesh

[1.0.4] - 2017-10-09

Added

  • Optional staticWidth prop @thejettdurham.
  • Use prop-types package instead of deprecated react's PropTypes.

[1.0.3] - 2017-06-06

Added

  • Pass row index to renderItem @heaversm.

Acknowledgments

Colors in the example from https://flatuicolors.com/.

Screenshot Mockup generated from https://mockuphone.com.

react-native-super-grid's People

Contributors

acollazomayer avatar andersonaddo avatar annepham25 avatar ataillefer avatar budiadiono avatar dependabot[bot] avatar devchanq avatar grohden avatar heaversm avatar ianmartorell avatar isaax avatar jeffgukang avatar josemiguelo avatar julienkode avatar komse avatar leezumstein avatar levic92 avatar lightenedlimited avatar m-tymchyk avatar mannycolon avatar mattyk14 avatar miracle2k avatar paldepind avatar paulrostorp avatar saleel avatar sanghavan avatar sh3rawi avatar thejettdurham avatar wjaykim avatar zhigang1992 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-super-grid's Issues

Is SectionHeader supported?

@saleel :
Hi, is SectionHeader supported?
being that I have to do a page system.
Example:
Page 1: the first twenty results
Page 2: the second twenty results
...

refresh?

can we call a refresh function like in standard scrollview in react native?

how to add press item handler

how can I add item click handler
I tried to this way, but not working

<GridView
itemDimension={150}
items={this.items}
style={styles.gridView}
renderItem={item => (

{item.name}

)}
/>

GridView inside a View

How can I do this?

return (
  <View>
   <View><Text>Header</Text></View>
      <GridView
        itemDimension={130}
        items={items}
        style={styles.gridView}
        renderItem={item => (
          <View style={[styles.itemContainer, { backgroundColor: item.code }]}>
            <Text style={styles.itemName}>{item.name}</Text>
            <Text style={styles.itemCode}>{item.code}</Text>
          </View>
        )}
      />
  </View>
);

I am trying to use react navigation with react-native-super-grid getting error Cannot read property 'navigate' of undefined

This is my render block
` render() {

    let items = this.state.products;
   // const navigation = this.props.navigation



   if (this.state.ProductsLoaded === true){
       return  (

           <View style={styles.productContainer}>
               <Text style={styles.productContainerTitle}>Best Selling Mobiles</Text>
               <GridView
                   itemDimension={140}
                   items={items}
                   style={styles.gridView}
                  


                   renderItem={item => (
                       <TouchableOpacity style={[styles.itemContainer, { backgroundColor: '#ffffff' }]}
                                         onPress={() => this.props.navigation.navigate('About')}



                       >
                           <Image
                               style={styles.ProductImage}
                               source={{uri: item.product_primary_images.cdn_url }}
                           >

                           </Image>
                           <Text style={styles.itemName}>{item.name.slice(0,15)}</Text>
                           <Text style={styles.itemPrice}>
                               ₹ {item.listing_price}</Text><Text style={styles.itemPrice}>
                               ₹ {item.slug}</Text>
                       </TouchableOpacity>
                   )}
               />
           </View>

       )
   } else
    return (

           <View style={styles.productContainer}>
               <Text style={styles.productContainerTitle}>Best Selling Mobiles</Text>

               <View style={styles.gridViewLoading}>

                   <ActivityIndicator size="large" color="#4b8ccd" />

               </View>


           </View>

    );
}`

I am getting error Cannot read property 'navigate' of undefined

Spacing prop only affect horizontal spacing

When i changed spacing to 3, horizontal space becomes 3 but vertical space stays 10. There is a marginBottom: 10 styling on one of the views which is not affected from spacing prop.

Use a different method for deep cloning

Current method uses JSON.parse & JSON.stringify to deep clone the sections data:

//Deep copy, so that re-renders and chunkArray functions don't affect the actual items object
let sectionsCopy = JSON.parse(JSON.stringify(sections));

The problem is that it will not clone keys with assigned functions as their values. After I moved from the SectionList to the SuperGridSectionList I got a lot undefined properties in the renderItem and renderSectionHeader methods.

@saleel would you consider using something like lodash.clonedeep instead of the method I described above to solve this issue?

Is it possible to make an infinite list with this component?

I try use this component I am trying to use this component with an infinite list as it is handled with the FlatList but the onEndReachedThreshold works only once.

`import React, { Component } from 'react';
import { View, Text, Image, ActivityIndicator } from 'react-native';
import GridView from 'react-native-super-grid';
import PropTypes from 'prop-types';

class CardMarkResume extends Component {

constructor(props) {
super(props);
// this._infinityList = React.createRef();
this.viewabilityConfig = {
waitForInteraction: true,
viewAreaCoveragePercentThreshold: 0.1
};
}

_renderFooter = () => {
const { loading } = this.props;
if (!loading) return null;
return (
<View style={{ paddingVertical: 20, borderTopWidth: 1, borderColor: '#CED0CE' }} >


);
}

// uri:'https://unsplash.it/400/400/?random'

render() {

const { data, refreshing, loading, handleLoadMore } = this.props;

return (
<GridView
viewabilityConfig={this.viewabilityConfig}
itemDimension={130}
items={data}
style={styles.gridView}
onEndReachedThreshold={0.1} // compatible con android no tocar
onEndReached={handleLoadMore}
refreshing={refreshing}
loading={loading}
ListFooterComponent={this._renderFooter}
renderItem={item => (

<Image style={{ position: 'absolute', height: 200, width: 200, resizeMode: 'cover' }} source={item.imagen} />
<View style={{ backgroundColor: 'rgba(51, 51, 51, 0.8)', padding: 6, flex: 1, maxHeight: 40, alignSelf: 'stretch' }}>
{item.Title}
$ {item.Precio}


)}
/>
);
}

}

const styles = {
gridView: {
paddingTop: 25,
flex: 1,
},
itemContainer: {
justifyContent: 'flex-end',
padding: 10,
height: 150,
position: 'relative',
overflow: 'hidden'
},
itemName: {
fontSize: 16,
color: '#fff',
fontFamily: 'DINCond'
},
itemCode: {
fontFamily: 'DINMedium',
fontSize: 12,
color: '#fff',
},
};

CardMarkResume.propTypes = {
data: PropTypes.array.isRequired,
refreshing: PropTypes.bool,
loading: PropTypes.bool,
handleLoadMore: PropTypes.func
};

export { CardMarkResume };`

Multi Select

Hi can you please help me with this plugin to do multi selection

Grid columns don't update with dynamic data

Hi there so I have a list that is displaying data off firestore. When there is only one item it renders it in the middle of the page, correctly. However if I add more items to the collection the grid keep growing vertically. Refreshing the app (RR) updates the grid to display correctly horizontally with 2 columns.

Grid with only one item.
image

Grid with another item added.
image

Grid after refreshing the app entirely (RR).
image

I would expect this transition of a grid with one row to two rows to happen on a redraw rather then having to refresh the component/app entirely.

Here is the code for this component:

import React from 'react';
import {StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import FAB from 'react-native-fab'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import GridView from 'react-native-super-grid';
import {currentDashboardCollection, setUserPath} from "../api/firebase";

export default class Dashboard extends React.Component {
  constructor(props) {
    super(props);
    this.unsubscribe = null;
    this.state = {
      years: [],
      loading: true,
    };
  }

  componentDidMount() {
    setUserPath("").then( x => {
      currentDashboardCollection().then( res => {
        this.unsubscribe = res.onSnapshot(this.collectionUpdate)
      });
    });
  }

  componentWillUnmount() {
    if (this.unsubscribe) {
      this.unsubscribe();
    }
  }

  collectionUpdate = (snapshot) => {
    const years = [];
    snapshot.forEach((d) => {
      const { title, year } = d.data();
      years.push({ key: d.id, title, year });
    });
    years.sort((a,b) => { return a.year === b.year ? (a.title < b.title ? -1 : 1) : (a.year < b.year ? 1 : -1) });
    this.setState({ years, loading: false });
  };

  render() {
    const { years, loading } = this.state;
    const { navigate } = this.props.navigation;

    if (loading) {
      return (
        <View style={styles.container}>
          <Text>Loading</Text>
        </View>
      )
    }

    if (years.length === 0) {
      return (
        <View style={styles.container}>
          <Text>You have no years.</Text>
          <Text>Add your first year using the pink + button.</Text>
          <FAB buttonColor="#f214e2" iconTextColor="#FFFFFF" onClickAction={() => navigate("AddYear")} visible={true} iconTextComponent={<Icon name="plus"/>} />
        </View>
      )
    }

    return (
      <View style={styles.container}>
        <GridView
          itemDimension={150}
          spacing={15}
          items={years}
          style={styles.gridView}
          renderItem={item => (
            <TouchableOpacity
              style={styles.collectionItemContainer}
              onLongPress={() => navigate("EditYear", { title: item.title, year: item.year, id: item.key })}
              onPress={() => navigate("Year", { path: { yearId: item.key }})}
            >
              <Text style={styles.label}>{item.year}</Text>
              <Text style={styles.title}>{item.title}</Text>
            </TouchableOpacity>
          )}
        />
        <FAB buttonColor="#f214e2" iconTextColor="#FFFFFF" onClickAction={() => navigate("AddYear")} visible={true} iconTextComponent={<Icon name="plus"/>} />
      </View>
    );
  }
}

//Styles taken from: https://github.com/saleel/react-native-super-grid
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fafafa',
  },
  gridView: {
    paddingTop: 15,
    flex: 1,
  },
  collectionItemContainer: {
    backgroundColor: '#b2b2b2',
    borderRadius: 5,
    padding: 10,
    paddingBottom: 20,
  },
  title: {
    fontSize: 16,
    fontWeight: '300',
  },
  label: {
    fontWeight: '900',
    fontSize: 44,
  },
});

Maybe I have done something wrong. Currently considering working around this by forcing the component to completely refresh.

Arrange item per row

nice grid!, greate work.

I gave a question, how to manual set item per row, example render view like this
[1] [2] [3] // 3 item per row fixed
[4] [5] [6]
[7] [8] [9]

thanks

Getting the index of the renderItem

Hi, this component is superb. Is there a way to get the item index of renderItem?

Something like in FlatList?

Ex:

<FlatList
    scrollEnabled={this.state.itemList.length > 3}
    data={this.state.itemList}
    keyExtractor={item => item.id}
    renderItem={({item, index}) => this.renderItem(item, index)} //Like This?
/>

TouchableOpacity onPress inside renderItem not working

I need to click item but its not working
here is my code

    _onPress = () => {
    // your code on item press
    console.log('wakaa')
 };
  _renderCategory(item) {
    return (
      <TouchableOpacity onPress={()=>this._onPress()}>
      <ImageBackground  source={{uri: `data:${item.productCategoryImageContentType};base64,${item.productCategoryImage}`}} resizeMode= 'stretch' style={[styles.itemContainer,]}>
      <Text style={styles.itemName}>{item.category}</Text>
      <Text style={styles.itemCode}>{item.description}</Text>
      </ImageBackground>
      </TouchableOpacity>
    )
  }

  render () {
    return (
      <View style={styles.container}>
        <GridView
          style={styles.gridView}
          items={this.state.dataCategoryObjects}
          renderItem={this._renderCategory}
          onEndReached={this.handleLoadMore}
          keyExtractor={this.keyExtractor}
          initialNumToRender={this.oneScreensWorth}
          onEndReached={this.handleLoadMore}
          onEndThreshold={100}
          ListHeaderComponent={this.renderHeader}
          /* ListFooterComponent={this.renderFooter} */
          ListEmptyComponent={this.renderEmpty}
          ItemSeparatorComponent={this.renderSeparator}

     
  
        />

    
      </View>
    )
  }

and I am getting this error
screen shot 2018-10-23 at 7 03 57 pm

Multiple Grids Not Rendering Properly

So this is a bit of an odd one... I have a tabbed navigation consisting of three tabs, each page identical apart from the data being fed in to the list. The first two tabs that are mounted display perfectly but the third and subsequent lists don't display anything unless I first scroll up or down slightly. Only then, do the grid items appear.

Now I have gotten around this by adding the following property to the list view which seems to fix it:
removeClippedSubviews={false}

Any ideas what could be causing this? I'm using react-native-router-flux for the navigation and just a simple image as the components to render on the list.

Performance

This is more of a question, not an issue. Does the component re render upon rotation or not?
Thanks!

pass index to renderItem

the index from the data mapping function is useful in giving grid items different styles based on their index.

<View style={rowStyle}>
        {(data || []).map((item, i) => (
          <View key={`${rowId}_${i}`} style={columnStyle}>
            <View style={itemStyle}>
              {this.props.renderItem(item,i)}
            </View>
          </View>
        ))}
      </View>

Since it is already accessible, suggest passing it along

Do not specify the size but the number of items per line.

@saleel :
Hi, congratulations on the module.
I wanted to ask, but if instead of specifying the size I wanted, specify the number of elements per row regardless of the size of the screen, whether this is large or small.

For example, 5 items per line.
Should you do?

Code:

import React, { Component } from 'react';
import { Text, View, StyleSheet, Image, Dimensions } from 'react-native';
//import { Constants } from 'expo';
import GridView from 'react-native-super-grid'; // 2.0.1

const Actor =
 [{id:90633,name:"Gal Gadot",profile_path:"/yV2nljqQa3MjrrIK4AllDjmJIcs.jpg"},
 {id:62064,name:"Chris Pine",profile_path:"/vSe6sIsdtcoqBhuWRXynahFg8Vf.jpg"},
 {id:32,name:"Robin Wright",profile_path:"/tXfQTgcIEPP7gtVdJ44ZxZPhacn.jpg"},
 {id:6413,name:"Danny Huston",profile_path:"/jc1eGtCShQ2ZkzqWApiWbA1lbTF.jpg"},
 {id:11207,name:"David Thewlis",profile_path:"/lWCGcTKvr4QUi8MvFBleMw8xY8.jpg"},
 {id:935,name:"Connie Nielsen",profile_path:"/lvQypTfeH2Gn2PTbzq6XkT2PLmn.jpg"},
 {id:3623,name:"Elena Anaya",profile_path:"/67brgegoJLcIQKiu4EEGtNymaUj.jpg"},
 {id:1829985,name:"Lilly Aspell",profile_path:"/rZ8BTHLatm8dtZus4HZFv7GsSuA.jpg"},
 {id:1590758,name:"Emily Carey",profile_path:"/esIqsc1XmBRPo07e95C6ebxLD7A.jpg"},
 {id:11111,name:"Lucy Davis",profile_path:"/3Qpcq4Pu8lKXtHxtUEHqyOuibbn.jpg"},
 {id:5419,name:"Saïd Taghmaoui",profile_path:"/bOh3ZQ64WiGivN6GJrrO8vrw9wU.jpg"},
 {id:1125,name:"Ewen Bremner",profile_path:"/7CQBnBHSNDcbY2LucqWqEpKWsCH.jpg"},
 {id:1823591,name:"Eugene Brave Rock",profile_path:"/27RL3pfNTBTu2zeNvFQTLFvCrJv.jpg"},
 {id:1310711,name:"Lisa Loven Kongsli",profile_path:"/pwT0UuQ1tsleh3urfabVRj0UE3S.jpg"},
 {id:139900,name:"Florence Kasumba",profile_path:"/oLKR9435H3sjeCWWvD0rLGsL5t9.jpg"},
 {id:1767342,name:"Madeleine Vall",profile_path:"/jACXQG2xHuFeIoxgGGhUbbrZNl1.jpg"},
 {id:1831280,name:"Hayley Warnes",profile_path:"/2dPqpifxaxXc6urLimtC6bdkh5s.jpg"},
 {id:1767343,name:"Ann Wolfe",profile_path:"/5VVXr5NOSqC0uMxXoXFrIA9eKe8.jpg"},
 {id:1009999,name:"Doutzen Kroes",profile_path:"/1aXyxlwPZ6OWaO67gdPBT0K2bAS.jpg"},
 {id:1272968,name:"Samantha Jo",profile_path:"/aHUB2vNo5ZbOVnlmqJ4SkUpDXrk.jpg"},
 {id:1360156,name:"Ann Ogbomo",profile_path:"/5EGoq8xksh6w1MZJBDgEi7LofDC.jpg"},
 {id:62976,name:"Eleanor Matsuura",profile_path:"/6ZbBU8ESZw8wTOdmqF9WJd2I9Gt.jpg"},
 {id:174708,name:"Josette Simon",profile_path:"/rtFA2jn0d69EL5GVGukTHSlE4Kl.jpg"},
 {id:1831281,name:"Brooke Ence",profile_path:"/1FBI6wg4dV2O8Z5NroCFLoVQ6m1.jpg"},
 {id:1831282,name:"Hari James",profile_path:"/q9OXpOaCX2t6cCLr8PO8r53j4YL.jpg"},
 {id:1813935,name:"Jacqui-Lee Pryce",profile_path:"/3lp7b4ncDVQYjAkgRmxI3DmBz9L.jpg"},
 {id:2467,name:"James Cosmo",profile_path:"/523gSqAG9eSSNmKexFFZYh38SxL.jpg"},
 {id:1831379,name:"Martin Bishop",profile_path:"/9a0beQcrkxENGKWJ4z3th25JBjO.jpg"},
 {id:1256710,name:"Flora Nicholson",profile_path:"/DT171ClURqTp1sHvliV5oije1X.jpg"},
 {id:143892,name:"Steffan Rhodri",profile_path:"/4bptQdwRKCMveddkpZdCvDwcsHQ.jpg"},
 {id:1232889,name:"Rachel Pickup",profile_path:"/paSFHcLTDBmR6n04bIpCyJA3rSA.jpg"},
 {id:65054,name:"Rainer Bock",profile_path:"/ebmPZimivfRFKYnKp2ygazkJO9r.jpg"},
 {id:1831283,name:"Eva Dabrowski",profile_path:"/oqZlnfADX2TLptomZmUXKj8xBzp.jpg"},
 {id:1857866,name:"Kattreya Scheurer-Smith",profile_path:"/n1cwG4jJoeN5lxmNSFjC9cKIVWf.jpg"},
 {id:1890510,name:"Betty Adewole",profile_path:"/ncvgnSmpJ0IhtcuaKp2WtkZF9lh.jpg"},
 {id:1431128,name:"Caroline Maria Winberg",profile_path:"/fXeuNhThb61khaAoccPf59ODLgz.jpg"},
 {id:1690518,name:"Rekha Luther",profile_path:"/xadtWM2vvrhDHZ8gcdghPZsglsJ.jpg"},
 {id:1890409,name:"Ooooota Adepo",profile_path:"/nWmpjYNQuSG8Kx0FuL37PVvCYNr.jpg"},
 {id:1813934,name:"Zinnia Kumar",profile_path:"/dHkO6v9Nh6LfsBaZTpK2nNZ7v82.jpg"},
 {id:1830144,name:"Andrea Vasiliou",profile_path:"/r4g0Hw0pzomj8UuLO3D9tNvkO98.jpg"},
 {id:1890511,name:"Freddy Elletson",profile_path:"/8lw4YgcBZeFKZ2SYLJ71TobDuSI.jpg"},
 {id:1890513,name:"Sammy Hayman",profile_path:"/g2y6domOIIdAht8wfmKmNtNE0WE.jpg"},
 {id:1861352,name:"Michael Tantrum",profile_path:"/vfSkp365hUfTTLF5Ye33zGjbNNf.jpg"},
 {id:157826,name:"Philippe Spall",profile_path:"/9dNHdrBLr6hY8Vf0bHS5h8mrQzA.jpg"},
 {id:1824289,name:"Edward Wolstenholme",profile_path:"/9Acyyk5gIN8qGlQ4VuPZ6VCgw3A.jpg"},
 {id:1643761,name:"Jennie Eggleton",profile_path:"/rgLqGrIF6DH4rwKIXMjqT1kVB59.jpg"},
 {id:1824290,name:"Frank Allen Forbes",profile_path:"/eBzMDu8kskfefTfl95NukYEVqMh.jpg"},
 {id:1824295,name:"Jemma Moore",profile_path:"/9p0GWc7hIgnjt0Ua5zvH1n7hLXU.jpg"},
 {id:1890450,name:"Caitlin Burles",profile_path:"/k508jIWbCk6HOliJklZJS3KqPRn.jpg"},
 {id:1562095,name:"Ulli Ackermann",profile_path:"/nH3l4SM06Xel28UtVyiRfFIZYAr.jpg"},
 {id:1820151,name:"Marko Leht",profile_path:"/34Hfcm5xJzFYIM6A5iNuso1aBaZ.jpg"},
 {id:659,name:"Wolf Kahler",profile_path:"/uqHI2PLeGFxdjlw0qIk1D17NjWb.jpg"},
 {id:1040480,name:"Dominic Kinnaird",profile_path:"/kRsj6Wm9BzzjIQqlOhndtuwnPCZ.jpg"},
 {id:1890458,name:"Fred Fergus",profile_path:"/31rOvizxOVC68pYPfXChHiEt7M.jpg"},
 {id:1824301,name:"Freddy Carter",profile_path:"/u4Ibhf8LnRzfuR2IUx6ZQWdWaVv.jpg"},
 {id:75256,name:"Ian Hughes",profile_path:"/jQXF27nYEsCAmdFyqJVOKbHZFxf.jpg"},
 {id:1052209,name:"Andrew Byron",profile_path:"/yOoY7YAfKzLfJIw9dOyvczH2xmi.jpg"},
 {id:1890493,name:"Amber Doyle",profile_path:"/NKO2Q0il3Hj5IFb2jK3LdTAWuU.jpg"},
 {id:1171527,name:"Alexander Mercury",profile_path:"/pz3zmiT79qnvGyPUsR6iZkBVf6W.jpg"},
 {id:1457240,name:"Gana Bayarsaikhan",profile_path:"/rc7jskbwC1Bn1Uy8iIL4dU0NqFH.jpg"},
 {id:1726321,name:"Camilla Roholm",profile_path:"/feaxjgK6F8egTGwlmrZHvN9TftR.jpg"},
 {id:1743363,name:"Sofia Abbasi",profile_path:null},
 {id:1702788,name:"Georgina Armstrong",profile_path:"/kXLYB8o6nfouKmy690MGDcdNtQo.jpg"},
 {id:1743575,name:"Annarie Boor",profile_path:"/mioZHOK2wXGOVc6Ue3pHnahR5Iz.jpg"},
 {id:1824293,name:"Harry Brewis",profile_path:null},
 {id:1502439,name:"Bern Collaco",profile_path:"/ziLGGjo5GWzYDL8H4MUquoFj8r0.jpg"},
 {id:555133,name:"Steve Doyle",profile_path:"/zzAmMr1QsKxbcYgobH05rQGuXnh.jpg"},
 {id:1592480,name:"Dino Fazzani",profile_path:"/fjOF76fBGDAKMGeGkuK4HUkLgrx.jpg"},
 {id:1624443,name:"Flor Ferraco",profile_path:"/gzwL8y0OT6GDkE5rNAlnXxP2u5m.jpg"},
 {id:1527565,name:"Mayling Ng",profile_path:"/jevQBPkbeaCsNs8KPrO9mxok983.jpg"},
 {id:1651414,name:"Sternkiker François",profile_path:"/8EcUOLAJ7QpVa9LN4vqoCxd0QQf.jpg"},
 {id:1743593,name:"David Georgiou",profile_path:"/eT2ckxteHfwqjCkUNu0FiG643tv.jpg"},
 {id:1651385,name:"Roman Green",profile_path:"/uUd7UsRw94bvbluAkntDDdOJpM0.jpg"},
 {id:1651394,name:"Shane Griffin",profile_path:null},
 {id:1824297,name:"Steve Healey",profile_path:null},
 {id:1824294,name:"Karl Fredrick Hiemeyer",profile_path:null},
 {id:1502441,name:"Kornelia Horvath",profile_path:"/gDimAObmWPSsFRyaSg40QlDMUNI.jpg"},
 {id:1284323,name:"Kevin Hudson",profile_path:"/1OrwAIDUYbwZXOWbF5FZtgGMsCI.jpg"},
 {id:1820018,name:"Tim Ingall",profile_path:"/8TBgeYKRItgEkioHaXtSZerFjKM.jpg"},
 {id:1824291,name:"Ben Kelleher",profile_path:"/hCxzMivfpFlua0m2b25yQBKjKkr.jpg"},
 {id:1813664,name:"John Kinory",profile_path:null},
 {id:1824300,name:"Dario A. Lee",profile_path:null},
 {id:1809569,name:"Christopher Marsh",profile_path:null},
 {id:1699114,name:"Lora Moss",profile_path:"/5j9isIvOyO3EuhBhNxNQToGL4ip.jpg"},
 {id:1809570,name:"James M.L. Muller",profile_path:"/b7nuAf9fhZyp6oF09NrGA87vkg4.jpg"},
 {id:1735654,name:"Ekran Mustafa",profile_path:null},
 {id:1702759,name:"Shaun Newnham",profile_path:null},
 {id:1809572,name:"Yves O'Hara",profile_path:null},
 {id:1461309,name:"Rajeev Pahuja",profile_path:"/oHXsxs3quaESZXjrFRk0FGHuAO0.jpg"},
 {id:1785923,name:"Jag Patel",profile_path:"/uChgXgHBAFBsy3a9NrCiL0klPMS.jpg"},
 {id:1635870,name:"Richard Price",profile_path:"/iiITgdpWPmybUfhWd1ktjxDFW1c.jpg"},
 {id:1451618,name:"Anthony J. Sacco",profile_path:"/nRUNvLCfe43Rs1OEd4GoztuxxED.jpg"},
 {id:1824303,name:"Adam Sef",profile_path:null},
 {id:147641,name:"Mick Slaney",profile_path:null},
 {id:15217,name:"Zack Snyder",profile_path:"/vdr0DlKJH4Ub7nWZtkanBH65bGH.jpg"},
 {id:1824299,name:"Fran Targ",profile_path:"/83eaNik8vdvHCyeUmEo5GfBiVOR.jpg"},
 {id:29333,name:"Roy Taylor",profile_path:"/eac87ztd0AcxBLvJPsCoNsvOzVc.jpg"},
 {id:1824296,name:"Roy Martin Thorn",profile_path:null},
 {id:1824302,name:"Phil Tillott",profile_path:null},
 {id:1635843,name:"Matt Townsend",profile_path:"/oAwLdyE519RGtg2bwvoKEZomMOM.jpg"},
 {id:1756412,name:"Ray Whelan",profile_path:"/isPM6LslVwFVnDvE8esxAqNJWJR.jpg"},
 {id:1743005,name:"Tom Whelehan",profile_path:null},
 {id:1824304,name:"Zac Whitehead",profile_path:null},
 {id:1651386,name:"Miroslav Zaruba",profile_path:"/kZyZlbiFGoatmZSpeiYjm4hLhlu.jpg"},
 {id:590410,name:"Lee Neville",profile_path:"/2CR8faSmvsACfaQg05HWDZo4uEc.jpg"}];

var { width} = Dimensions.get('window');

export default class App extends Component {
  render() {
    return (
      <GridView
        itemDimension={width/5-20}
        items={Actor}
        style={styles.gridView}
        fixed={true}
        renderItem={item => (
          <View style={[styles.itemContainer, { backgroundColor: '#fff' }]}>
          <Image style={{
            textAlign: 'center',
            borderTopLeftRadius: 4,
            borderTopRightRadius: 4,
            height: 150,
            width: width/5-20 }} 
            source={{
              uri: (item.profile_path == null) ?
            'https://techreport.com/forums/styles/canvas/theme/images/no_avatar.jpg' :
            'https://image.tmdb.org/t/p/w185/'+item.profile_path
            }}
            />
            <Text numberOfLines={2} ellipsizeMode={'tail'} style={styles.itemName}>{item.name}</Text>
          </View>
        )}
      />
    );
  }
}
const styles = StyleSheet.create({
  gridView: {
    //paddingTop: 25,
    flex: 1,
  },
  itemContainer: {
    //justifyContent: 'flex-end',
    borderRadius: 4,
    //padding: 10,
    height: 180,
    elevation: 2,
    overflow: 'hidden', 
    //backgroundColor: "#fff", marginTop: 5, marginLeft: 8 
  },
  itemName: {
    fontSize: 10,
    textAlign: 'center',
    color: '#444',
    //fontWeight: '600',
  },
});

Link expo: https://snack.expo.io/H1_bIs-Vf

How to set an item onTap callback?

Hello, many thanks for you work!

I have two questions:

  1. how to set a item onTap callback?

  2. Any chance to have add/del item functionality?

Thanks again.

Grid header

Would be great to support a grid header similar to the ListHeaderComponent of the section list component.

Section header is overlap with item on iOS

I'm try to render the grid by this snippet

const gridSectionRenderer = ({ section }) => {
  return (
    <Text style={[styles.CommonHeaderText, { fontSize: 25 }]}>
      {section.SectionName}
    </Text>
  );
};

    <SuperGridSectionList
          itemDimension={130}
          sections={this.state.data}
          style={styles.gridView}
          renderItem={gridViewRenderer}
          renderSectionHeader={gridSectionRenderer}
        />

and it's work just fine on Android
screenshot_1535511220

still, the problem only occur on iOS just like the picture below
prob

any idea what happening or causing this? any help would be appreciated.

Set custom height to the grid images

I need to show my grid images in 4:5 ratio (width:height). So, I need to set own height (width/4*5) value to the grid images at runtime. Is there s way to do this?

<GridView
        spacing={0}
        itemDimension={screenWidth/2}
        items = {this.renderItems()}
        style={styles.gridView}
        renderItem={this.renderGrid.bind(this)}
     />

Infinite scroll

First I wanted to say it's a great component, second is there a method that can be used to load more items I would like to setup an infinite scroll where I load more photos from an API call.

Either a method when the end is reached or something like onLoadMoreAsync which is called at the end.

FlatList props are type error

When used in typescript, props that can be used with FlatList become type error (eg onEndReached, onEndReachedThreshold etc....).
Is this supposed to be? Is it supposed to be used in type script?
I am avoiding it using @ts-ignore now.
please tell me if there is a way to extend it well.

how to navigate between screen

i want navigate between screen,
click grid quotes from home navigate to quotes
click grid contact from home navigate to contact

Home.js


import React, {Component} from 'react';
import {Text,View,StyleSheet,TouchableOpacity} from 'react-native';
import GridView from 'react-native-super-grid';

export default class Home extends Component {
  static navigationOptions = {
    title: 'Welcome',
  };
  render() {
    const {navigate} = this.props.navigation;
    
    const items = [
      { name: 'Quotes', code: '#1abc9c' ,id: Math.random() }, { name: 'EMERALD', code: '#2ecc71',id : Math.random() },
     
    ];
  
    onPress = () => {
      this.props.navigation.navigate('quotes')
    }

    return (
      <GridView 
          itemDimension={130}
          items={items}
          style={styles.gridView}
          renderItem={item => (
            <TouchableOpacity key={item.id}  onPress={this.onPress}> 
            <View style={[styles.itemContainer, { backgroundColor: item.code }]}>
              <Text style={styles.itemName}>{item.name}</Text>
              <Text style={styles.itemCode}>{item.code}</Text>
            </View>
          </TouchableOpacity>
          )}
          
          />
    );
  }
}

const styles = StyleSheet.create({
  gridView: {
    paddingTop: 25,
    flex: 1,
  },
  itemContainer: {
    justifyContent: 'flex-end',
    borderRadius: 5,
    padding: 10,
    height: 150,
  },
  itemName: {
    fontSize: 16,
    color: '#fff',
    fontWeight: '600',
  },
  itemCode: {
    fontWeight: '600',
    fontSize: 12,
    color: '#fff',
  },
});

quotes.js

import React,{Component} from 'react';
import {Text} from 'react-native';

export default class Quotes extends Component {
    render(){

        return(
            <Text>Quotes</Text>
        )
    }
}

parentnavigations.js

import React,{Component} from 'react';
import {createStackNavigator,StackNavigator} from 'react-navigation';
import Intro from '../Screen/Intro';
import HomeScreen from '../Screen/Home';
import QuotesScreen from '../Screen/Quotes';

export default logStack = StackNavigator({

    Intro : {
        
        screen : Intro
    },
    Home : {
        screen : HomeScreen
    },
    Quote : {
        screen : QuotesScreen
    }


},{
    initialRouteName : 'Intro',
    navigationOptions : {
        header : null
    }
})


Header sections

Is it possible to add or create header sections? I would like to load photos but in a date section

View.PropTypes deprecated APK release crash on 0.49 ++

The current package not working with 0.49++, the problem caused by View.PropTypes deprecated.
solution :

  • add import { View, ListView, Dimensions, ViewPropTypes } from 'react-native';
  • change the style: View.PropTypes.style to style: ViewPropTypes.style,

Ability to render a grid inside an existing ScrollView

Hi,

Current implementation always use a FlatList.

It's like to reuse the grid abilities of this lib but just render items as-is without providing an extra scrollable container.

My usecase is to render a list of photos (small amount, no virtualization needed) as a responsive grid inside an existing scrollable container (which also has a parallax header animation). The grid is not the only element of this scrollview and I can't really use a FlatList header for that.

Clear grid view

Is there a method to clear or remove items from the gridview, for example I have an api call that updates with new photos when that method is called I would like to delete the current contents of the gird view

[Proposal] Optional prop for static container width

Great work on this component! It saved me a good amount of time designing a responsive grid component from the ground up. I did have one small issue with it: the noticeable flicker between when the component is constructed (before it knows the width of its parent) and after it's onLayout event fires. I understand why this happens and that there's not a good general solution for it, but this can be avoided if the container width could be passed to the GridView as a prop.

My use case is rendering a GridView into a container that is half the width of the display, and that width can't be changed at runtime (orientation is locked to landscape). The actual width of this container will vary between devices, but it's absolute width can always be calculated at runtime by Dimensions.get('window').width / 2, without the need for onLayout events. If I could pass this calculation to GridView as a prop, it could be used to initialize the GridView's state, and the subsequent onLayout triggers could be skipped. In this case, the grid will render as expected the first time without flickering.

Does this sound useful in general, or am I potentially using the wrong component to accomplish this? If this does sound good, I have an implementation I can provide via a PR.

Thanks again!

Render Dynamic Data

I'm playing with this nice module you've made and looking to implement this in the app I'm working on. I'm currently fetching the JSON objects and rendering the RN default ListView, but I'm trying to use this to do the same thing.

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.