Code Monkey home page Code Monkey logo

react-native-responsive-grid's Introduction

React Native Responsive Grid

version npm npm npm npm

The best responsive grid component for react-native and react-native-web.

Installation

Using yarn:

yarn add react-native-responsive-grid-component

Using npm:

npm install react-native-responsive-grid-component --save

Example

Check the following example to see it in action and try changing the default props to see how it works.

npm

Usage

First of all, you need to wrap your root component with the GridProvider.

import React from "react";
import { GridProvider } from "react-native-responsive-grid-component";

const App = () => {
  return (
    <GridProvider>
      {/* your content */}
    </GridProvider>
  );
};

Then you can use the Grid component in the rest of your app.

How to use it

First way

You can use directly the Grid component as in the following example.

import React from "react";
import { View, StyleSheet } from "react-native";
import { Grid } from "react-native-responsive-grid-component";

const App = () => {
  return (
    <Grid>
      {Array.from(Array(20).keys()).map((item, index) => {
        return (
          <View style={styles.card} />
        );
      })}
    </Grid>
  );
};

const styles = StyleSheet.create({
  card: {
    backgroundColor: "white",
    borderRadius: 8,
    minHeight: 200,
    overflow: "hidden",
    shadowColor: "#000",
    shadowOffset: {
      width: 0,
      height: 2,
    },
    shadowOpacity: 0.25,
    shadowRadius: 3.84,
    elevation: 5,
  },
});

Second way

You can use directly the Col and Row components as in the following example.

import React from "react";
import { View, StyleSheet } from "react-native";
import { Col, Row } from "react-native-responsive-grid-component";

const App = () => {
  return (
    <Row>
      {Array.from(Array(20).keys()).map((item, index) => {
        return (
          <Col>
            <View style={styles.card} />
          </Col>
        );
      })}
    </Row>
  );
};

const styles = StyleSheet.create({
  card: {
    backgroundColor: "white",
    borderRadius: 8,
    minHeight: 200,
    overflow: "hidden",
    shadowColor: "#000",
    shadowOffset: {
      width: 0,
      height: 2,
    },
    shadowOpacity: 0.25,
    shadowRadius: 3.84,
    elevation: 5,
  },
});

Properties

GridProvider

Prop Description Type Default
sizes The sizes of the Col component for each screen size. SizesProps { xs: 12, sm: 6, md: 4, lg: 3, xl: 2 }
breakpoints The breakpoints for each screen size. SizesProps { xs: 500, sm: 730, md: 960, lg: 1450 }
padding The padding between the elements in the grid. number 16
showBreakpoints Whether to show or not the breakpoints (for development purpouses). boolean false
breakpointsColor The color of the breakpoints. string black

Grid

Accepts any View prop and the following.

Prop Description Type Default
xs Number of columns (between 0 and 12) that the each item should take in screens of size xs. number The one defined in the sizes prop of the GridProvider.
sm Number of columns (between 0 and 12) that the each item should take in screens of size sm. number The one defined in the sizes prop of the GridProvider.
md Number of columns (between 0 and 12) that the each item should take in screens of size md. number The one defined in the sizes prop of the GridProvider.
lg Number of columns (between 0 and 12) that the each item should take in screens of size lg. number The one defined in the sizes prop of the GridProvider.
xl Number of columns (between 0 and 12) that the each item should take in screens of size xl. number The one defined in the sizes prop of the GridProvider.
padding The padding between the elements in the grid. number The one defined in the padding prop of the GridProvider.
rowStyle Style for the Row component inside the grid. StyleProp<ViewStyle>
colStyle Style for the Col components inside the grid. StyleProp<ViewStyle>

Col

Accepts any View prop and the following.

Prop Description Type Default
xs Number of columns (between 0 and 12) that the each item should take in screens of size xs. number The one defined in the sizes prop of the GridProvider.
sm Number of columns (between 0 and 12) that the each item should take in screens of size sm. number The one defined in the sizes prop of the GridProvider.
md Number of columns (between 0 and 12) that the each item should take in screens of size md. number The one defined in the sizes prop of the GridProvider.
lg Number of columns (between 0 and 12) that the each item should take in screens of size lg. number The one defined in the sizes prop of the GridProvider.
xl Number of columns (between 0 and 12) that the each item should take in screens of size xl. number The one defined in the sizes prop of the GridProvider.

Row

Accepts any View prop.

License

MIT

react-native-responsive-grid's People

Contributors

nicolaslazzos avatar

Stargazers

Roman avatar

Watchers

 avatar

react-native-responsive-grid's Issues

Importing GridProvider gives error

I am trying to use this library in my project, but am getting the following error when I try to import GridProvider in App.js
Please let me know what needs to be done here, the docs do not mention anything about configuring a loader for this library.

.../node_modules/@nlazzos/react-native-responsive-grid/lib/Row.js 40:12
Module parse failed: Unexpected token (40:12)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     var { style, children } = _a, props = __rest(_a, ["style", "children"]);
|     const { padding } = Provider_1.useGrid();
>     return (<react_native_1.View {...props} style={[styles.row, { marginRight: -padding }, style]}>
| 			{children}
| 		</react_native_1.View>);

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.