├── .babelrc ├── .gitignore ├── .travis.yml ├── ChangeLog.md ├── Components ├── Col.js ├── Grid.js ├── Row.js └── _tests_ │ ├── Col.test.js │ ├── Grid.test.js │ ├── Row.test.js │ └── __snapshots__ │ ├── Col.test.js.snap │ ├── Grid.test.js.snap │ └── Row.test.js.snap ├── Examples ├── col-33-33-33.png ├── col-50-50.png ├── col-fluid-fixed.png ├── complex.png ├── row-50-25-25.png ├── row-50-50.png └── row-75-25.png ├── ISSUE_TEMPLATE.txt ├── LICENSE ├── README.md ├── Utils └── computeProps.js ├── index.d.ts ├── index.js └── package.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### OSX ### 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | 10 | # Thumbnails 11 | ._* 12 | 13 | # Files that might appear in the root of a volume 14 | .DocumentRevisions-V100 15 | .fseventsd 16 | .Spotlight-V100 17 | .TemporaryItems 18 | .Trashes 19 | .VolumeIcon.icns 20 | 21 | # Directories potentially created on remote AFP share 22 | .AppleDB 23 | .AppleDesktop 24 | Network Trash Folder 25 | Temporary Items 26 | .apdisk 27 | 28 | 29 | ### Node ### 30 | # Logs 31 | logs 32 | *.log 33 | npm-debug.log* 34 | 35 | # Runtime data 36 | pids 37 | *.pid 38 | *.seed 39 | 40 | # Directory for instrumented libs generated by jscoverage/JSCover 41 | lib-cov 42 | 43 | # Coverage directory used by tools like istanbul 44 | coverage 45 | 46 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 47 | .grunt 48 | 49 | # node-waf configuration 50 | .lock-wscript 51 | 52 | # Compiled binary addons (http://nodejs.org/api/addons.html) 53 | build/Release 54 | 55 | # Dependency directories 56 | node_modules 57 | jspm_packages 58 | 59 | # Optional npm cache directory 60 | .npm 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | 66 | ### Xcode ### 67 | # Xcode 68 | # 69 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 70 | 71 | ## Build generated 72 | build/ 73 | DerivedData/ 74 | 75 | ## Various settings 76 | *.pbxuser 77 | !default.pbxuser 78 | *.mode1v3 79 | !default.mode1v3 80 | *.mode2v3 81 | !default.mode2v3 82 | *.perspectivev3 83 | !default.perspectivev3 84 | xcuserdata/ 85 | 86 | ## Other 87 | *.moved-aside 88 | *.xccheckout 89 | *.xcscmblueprint 90 | 91 | 92 | ### Android ### 93 | # Built application files 94 | *.apk 95 | *.ap_ 96 | 97 | # Files for the Dalvik VM 98 | *.dex 99 | 100 | # Java class files 101 | *.class 102 | 103 | # Generated files 104 | bin/ 105 | gen/ 106 | out/ 107 | 108 | # Gradle files 109 | .gradle/ 110 | build/ 111 | 112 | # Local configuration file (sdk path, etc) 113 | local.properties 114 | 115 | # Proguard folder generated by Eclipse 116 | proguard/ 117 | 118 | # Log Files 119 | *.log 120 | 121 | # Android Studio Navigation editor temp files 122 | .navigation/ 123 | 124 | # Android Studio captures folder 125 | captures/ 126 | 127 | # Intellij 128 | *.iml 129 | 130 | # Keystore files 131 | *.jks 132 | 133 | ### Android Patch ### 134 | gen-external-apklibs 135 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # [0.2.0](https://github.com/GeekyAnts/react-native-easy-grid/releases/tag/v0.2.0) 2 | 3 | ### Updated Features 4 | 5 | - Upgraded babel-jest to 23.2.0 6 | - Upgraded babel-preset-react-native to 4 7 | - Upgraded jest to 23.3.0 8 | - Upgraded react to 16.4.1 9 | - Upgraded react-native to 0.56.0 10 | - Upgraded react-test-renderer to 16.4.1 11 | 12 | 13 | ### Bug Fixes 14 | 15 | - Compatible with React Native 0.56, fixed `ReactNativePropRegistry` issue. 16 | -------------------------------------------------------------------------------- /Components/Col.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import React, {Component} from 'react'; 4 | import {View, TouchableOpacity, StyleSheet} from 'react-native'; 5 | import computeProps from '../Utils/computeProps'; 6 | 7 | 8 | export default class ColumnNB extends Component { 9 | prepareRootProps() { 10 | 11 | var flattenedStyle = StyleSheet.flatten(this.props.style) 12 | 13 | var type = { 14 | flexDirection: 'column', 15 | flex: (this.props.size) ? this.props.size : (flattenedStyle && flattenedStyle.width) ? 0 : 1, 16 | } 17 | 18 | var defaultProps = { 19 | style: type 20 | } 21 | return computeProps(this.props, defaultProps); 22 | 23 | } 24 | 25 | setNativeProps(nativeProps) { 26 | this._root.setNativeProps(nativeProps); 27 | } 28 | 29 | render() { 30 | if(this.props.onPress){ 31 | return( 32 | 34 | this._root = component} 36 | {...this.props} 37 | {...this.prepareRootProps()} 38 | >{this.props.children} 39 | 40 | ); 41 | } 42 | else{ 43 | return( 44 | this._root = component} 46 | {...this.props} 47 | {...this.prepareRootProps()} 48 | >{this.props.children} 49 | ); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Components/Grid.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import React, {Component} from 'react'; 4 | import {View, TouchableOpacity} from 'react-native'; 5 | import computeProps from '../Utils/computeProps'; 6 | import Col from './Col'; 7 | import Row from './Row'; 8 | 9 | 10 | export default class GridNB extends Component { 11 | prepareRootProps() { 12 | 13 | var type = { 14 | flex: 1, 15 | flexDirection: this.ifRow() ? 'column' : 'row' 16 | } 17 | 18 | var defaultProps = { 19 | style: type 20 | } 21 | 22 | return computeProps(this.props, defaultProps); 23 | 24 | } 25 | 26 | ifRow() { 27 | var row = false; 28 | React.Children.forEach(this.props.children, function (child) { 29 | if(child && child.type == Row) 30 | row = true; 31 | }) 32 | return row; 33 | } 34 | 35 | setNativeProps(nativeProps) { 36 | this._root.setNativeProps(nativeProps); 37 | } 38 | 39 | render() { 40 | if(this.props.onPress){ 41 | return( 42 | 43 | this._root = component} 45 | {...this.props} 46 | {...this.prepareRootProps()} 47 | >{this.props.children} 48 | 49 | ); 50 | } 51 | else{ 52 | return( 53 | this._root = component} 55 | {...this.props} 56 | {...this.prepareRootProps()} 57 | >{this.props.children} 58 | ); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Components/Row.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import React, {Component} from 'react'; 4 | import {View, TouchableOpacity, StyleSheet} from 'react-native'; 5 | 6 | import computeProps from '../Utils/computeProps'; 7 | 8 | 9 | export default class RowNB extends Component { 10 | prepareRootProps() { 11 | 12 | var flattenedStyle = StyleSheet.flatten(this.props.style) 13 | 14 | var type = { 15 | flexDirection: 'row', 16 | flex: (this.props.size) ? this.props.size : (flattenedStyle && flattenedStyle.height) ? 0 : 1, 17 | } 18 | 19 | var defaultProps = { 20 | style: type 21 | } 22 | return computeProps(this.props, defaultProps); 23 | 24 | } 25 | 26 | setNativeProps(nativeProps) { 27 | this._root.setNativeProps(nativeProps); 28 | } 29 | 30 | render() { 31 | if(this.props.onPress){ 32 | return( 33 | 35 | this._root = component} 37 | {...this.props} 38 | {...this.prepareRootProps()} 39 | >{this.props.children} 40 | 41 | ); 42 | } 43 | else{ 44 | return( 45 | this._root = component} 47 | {...this.props} 48 | {...this.prepareRootProps()} 49 | >{this.props.children} 50 | ); 51 | } 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Components/_tests_/Col.test.js: -------------------------------------------------------------------------------- 1 | import "react-native"; 2 | import React from "react"; 3 | import Col from "../Col"; 4 | import renderer from "react-test-renderer"; 5 | 6 | test("renders correctly", () => { 7 | const tree = renderer.create().toJSON(); 8 | expect(tree).toMatchSnapshot(); 9 | }); 10 | -------------------------------------------------------------------------------- /Components/_tests_/Grid.test.js: -------------------------------------------------------------------------------- 1 | import "react-native"; 2 | import React from "react"; 3 | import Grid from "../Grid"; 4 | import renderer from "react-test-renderer"; 5 | 6 | test("renders correctly", () => { 7 | const tree = renderer.create().toJSON(); 8 | expect(tree).toMatchSnapshot(); 9 | }); 10 | -------------------------------------------------------------------------------- /Components/_tests_/Row.test.js: -------------------------------------------------------------------------------- 1 | import "react-native"; 2 | import React from "react"; 3 | import Row from "../Row"; 4 | import renderer from "react-test-renderer"; 5 | 6 | test("renders correctly", () => { 7 | const tree = renderer.create().toJSON(); 8 | expect(tree).toMatchSnapshot(); 9 | }); 10 | -------------------------------------------------------------------------------- /Components/_tests_/__snapshots__/Col.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`renders correctly 1`] = ` 4 | 12 | `; 13 | -------------------------------------------------------------------------------- /Components/_tests_/__snapshots__/Grid.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`renders correctly 1`] = ` 4 | 12 | `; 13 | -------------------------------------------------------------------------------- /Components/_tests_/__snapshots__/Row.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`renders correctly 1`] = ` 4 | 12 | `; 13 | -------------------------------------------------------------------------------- /Examples/col-33-33-33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekyAnts/react-native-easy-grid/f9f9abf096ab6c18ed308785481de28fa5c8f09f/Examples/col-33-33-33.png -------------------------------------------------------------------------------- /Examples/col-50-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekyAnts/react-native-easy-grid/f9f9abf096ab6c18ed308785481de28fa5c8f09f/Examples/col-50-50.png -------------------------------------------------------------------------------- /Examples/col-fluid-fixed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekyAnts/react-native-easy-grid/f9f9abf096ab6c18ed308785481de28fa5c8f09f/Examples/col-fluid-fixed.png -------------------------------------------------------------------------------- /Examples/complex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekyAnts/react-native-easy-grid/f9f9abf096ab6c18ed308785481de28fa5c8f09f/Examples/complex.png -------------------------------------------------------------------------------- /Examples/row-50-25-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekyAnts/react-native-easy-grid/f9f9abf096ab6c18ed308785481de28fa5c8f09f/Examples/row-50-25-25.png -------------------------------------------------------------------------------- /Examples/row-50-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekyAnts/react-native-easy-grid/f9f9abf096ab6c18ed308785481de28fa5c8f09f/Examples/row-50-50.png -------------------------------------------------------------------------------- /Examples/row-75-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekyAnts/react-native-easy-grid/f9f9abf096ab6c18ed308785481de28fa5c8f09f/Examples/row-75-25.png -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ## I have gone through these following points 6 | - [] Check latest documentation: https://docs.nativebase.io/ 7 | - [] Check for existing open/closed issues for a possible duplicate before creating a new issue: https://github.com/GeekyAnts/react-native-easy-grid/issues 8 | - [] Use the latest React Native Easy Grid release 9 | - [] Check examples from NativeBase KitchenSink https://github.com/GeekyAnts/NativeBase-KitchenSink 10 | - [] For discussion purpose make use of NativeBase Slack: http://slack.nativebase.io/ 11 | - [] For queries related to theme, check [Theme Variables](https://docs.nativebase.io/docs/ThemeVariables.html) from Docs and live NativeBase Theme Editor http://nativebase.io/customizer/ 12 | 13 | ## Issue Description 14 | 15 | 16 | ### node, npm, package.json, xcode version 17 | 18 | ### Expected behaviour 19 | 20 | ### Actual behaviour 21 | 22 | ### Steps to reproduce 23 | 30 | 31 | ### Is the bug present in both iOS and Android or in any one of them? 32 | 33 | ### Any other additional info which would help us debug the issue quicker. 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Native Easy Grid 🐵 2 | ![Master Build Status](https://travis-ci.org/GeekyAnts/react-native-easy-grid.svg?branch=master)
3 | 4 | This is NOT-JUST-ANOTHER-GRID-LAYOUT library! We are trying to simplify flexbox with easier approach. 5 | 6 | ## Installation 7 | 8 | ``` 9 | npm install react-native-easy-grid --save 10 | ``` 11 | 12 | ## Usage 13 | 14 | ### Include the components 15 | 16 | ``` 17 | import { Col, Row, Grid } from "react-native-easy-grid"; 18 | ``` 19 | 20 | ### 1. Two columns (50% and 50%) 21 | 22 | ``` 23 | 24 | 25 | 26 | 27 | ``` 28 | 29 | ![col-50-50](Examples/col-50-50.png "Column 50% and 50% example") 30 | 31 | 32 | 33 | > Note: If you don't assign the size property, it defaults to equal width (or height) with its siblings 34 | 35 | ### 2. Two rows 36 | 37 | ``` 38 | 39 | 40 | 41 | 42 | ``` 43 | 44 | ![row-50-50](Examples/row-50-50.png "Row 50% and 50% example") 45 | 46 | 47 | ### 3. Two rows (75% and 25%) 48 | 49 | ``` 50 | 51 | 52 | 53 | 54 | ``` 55 | 56 | This is exactly same as 57 | 58 | ``` 59 | 60 | 61 | 62 | 63 | ``` 64 | 65 | ![row-75-25](Examples/row-75-25.png "Row 75% and 25% example") 66 | 67 | > Same concept applies to `` 68 | 69 | 70 | ### 4. Three columns (33.33% each) 71 | 72 | ``` 73 | 74 | 75 | 76 | 77 | 78 | ``` 79 | ![col-33-33-33](Examples/col-33-33-33.png "Column 33.33% each") 80 | 81 | ### 5. Three rows (50%, 25% and 25%) 82 | 83 | ``` 84 | 85 | 86 | 87 | 88 | 89 | ``` 90 | 91 | ![row-50-25-25](Examples/row-50-25-25.png "Row 50%, 25% and 50% example") 92 | 93 | ### 6. Nested Layout or Grid 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
12
3
104 | 105 | ``` 106 | 107 | 108 | 1 109 | 110 | 111 | 112 | 2 113 | 114 | 115 | 3 116 | 117 | 118 | 119 | ``` 120 | 121 | ![complex](Examples/complex.png "Complex and Nested Layouts") 122 | 123 | 124 | 125 | ### 7. Fixed width and fluid width combination 126 | 127 | ``` 128 | 129 | 130 | Fixed width 131 | 132 | 133 | Fluid width 134 | 135 | 136 | ``` 137 | 138 | ![col-fluid-fixed.png](Examples/col-fluid-fixed.png "Column fluid and fixed example") 139 | 140 | 141 | ### 8. Fixed height and fluid height combination 142 | 143 | ``` 144 | 145 | 146 | Fixed width 147 | 148 | 149 | Fluid width 150 | 151 | 152 | ``` 153 | 154 | Do you think anything could be simpler than that? This repo is part of our bigger project called [NativeBase.io](http://nativebase.io). Do check that! 155 | 156 | # Important note about usage with `` 157 | 158 | > Note: If you're using `` inside a ``, the height of the component would be flexible according to the content, though you can always apply the `height` styling. 159 | -------------------------------------------------------------------------------- /Utils/computeProps.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { StyleSheet } from "react-native"; 3 | import _ from 'lodash'; 4 | 5 | function computeProps(incomingProps, defaultProps) { 6 | // External props has a higher precedence 7 | var computedProps = {}; 8 | 9 | incomingProps = _.clone(incomingProps); 10 | delete incomingProps.children; 11 | 12 | var incomingPropsStyle = incomingProps.style; 13 | delete incomingProps.style; 14 | 15 | // console.log(defaultProps, incomingProps); 16 | 17 | if (incomingProps) _.merge(computedProps, defaultProps, incomingProps); 18 | else computedProps = defaultProps; 19 | 20 | // Pass the merged Style Object instead 21 | if (incomingPropsStyle) { 22 | var computedPropsStyle = {}; 23 | computedProps.style = {}; 24 | if (Array.isArray(incomingPropsStyle)) { 25 | _.forEach(incomingPropsStyle, style => { 26 | if (typeof style == "number") { 27 | _.merge(computedPropsStyle, StyleSheet.flatten(style)); 28 | } else { 29 | _.merge(computedPropsStyle, style); 30 | } 31 | }); 32 | } else { 33 | if (typeof incomingPropsStyle == "number") { 34 | computedPropsStyle = StyleSheet.flatten( 35 | incomingPropsStyle 36 | ); 37 | } else { 38 | computedPropsStyle = incomingPropsStyle; 39 | } 40 | } 41 | 42 | _.merge(computedProps.style, defaultProps.style, computedPropsStyle); 43 | } 44 | 45 | // console.log("computedProps ", computedProps); 46 | 47 | return computedProps; 48 | }; 49 | 50 | export default computeProps; 51 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare module "react-native-easy-grid" { 2 | 3 | import {Component} from "react"; 4 | import {ViewProperties} from "react-native"; 5 | 6 | export interface RowProps extends ViewProperties { 7 | size?: number 8 | onPress?: () => void 9 | } 10 | 11 | export interface ColProps extends ViewProperties { 12 | size?: number 13 | onPress?: () => void 14 | } 15 | 16 | export class Grid extends Component {} 17 | export class Row extends Component {} 18 | export class Col extends Component {} 19 | } 20 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 'use strict'; 3 | 4 | import Row from './Components/Row'; 5 | import Grid from './Components/Grid'; 6 | import Col from './Components/Col'; 7 | 8 | export { Row, Grid, Col } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-easy-grid", 3 | "description": "Easy React Native Layout & Grid for the Dumb", 4 | "version": "0.2.2", 5 | "private": false, 6 | "dependencies": { 7 | "lodash": "^4.17.15" 8 | }, 9 | "scripts": { 10 | "test": "jest" 11 | }, 12 | "jest": { 13 | "preset": "react-native", 14 | "modulePathIgnorePatterns": [ 15 | "acorn", 16 | "core-js", 17 | "isarray", 18 | "wordwrap", 19 | "convert-source-map", 20 | "source-map", 21 | "which", 22 | "assert-plus", 23 | "esprima", 24 | "path-exists", 25 | "glob", 26 | "object-assign", 27 | "repeating", 28 | "supports-color", 29 | "json-stable-stringify", 30 | "minimist", 31 | "duplexer2", 32 | "readable-stream", 33 | "extend", 34 | "lru-cache", 35 | "minimatch", 36 | "async", 37 | "punycode", 38 | "clone", 39 | "graceful-fs", 40 | "strip-bom", 41 | "through2", 42 | "vinyl", 43 | "camelcase" 44 | ] 45 | }, 46 | "devDependencies": { 47 | "babel-eslint": "^6.0.4", 48 | "babel-jest": "23.2.0", 49 | "babel-preset-react-native": "4.0.0", 50 | "eslint": "^2.9.0", 51 | "eslint-plugin-react": "^5.0.1", 52 | "eslint-plugin-react-native": "^1.0.0", 53 | "jest": "23.3.0", 54 | "react": "16.4.1", 55 | "react-native": "^0.60.4", 56 | "react-test-renderer": "16.4.1" 57 | }, 58 | "repository": { 59 | "type": "git", 60 | "url": "https://github.com/GeekyAnts/react-native-easy-grid.git" 61 | }, 62 | "main": "index.js" 63 | } 64 | --------------------------------------------------------------------------------