Skip to content

Commit

Permalink
add script to watch and update src
Browse files Browse the repository at this point in the history
  • Loading branch information
gusgard committed Nov 19, 2017
1 parent 5059f09 commit 68cb30c
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
'consistent-return': 1,
'global-require': 0,
'import/extensions': [2, 'never'],
'import/no-extraneous-dependencies': ['error', { packageDir: './' }],
'import/no-extraneous-dependencies': 'off',
'import/no-unresolved': [2, { ignore: ['@'] }],
'import/prefer-default-export': 'off',
'import/no-named-as-default-member': 'off',
Expand Down
74 changes: 64 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,76 @@
![Travis](https://travis-ci.org/gusgard/react-native-grid-list.svg?branch=master)
# :godmode: Grid list component

# Installation
<p align="left">
<a href="https://npmjs.org/package/react-native-grid-list"><img alt="npm version" src="http://img.shields.io/npm/v/react-native-grid-list.svg"></a>
<a href="https://npmjs.org/package/react-native-grid-list"><img alt="npm version" src="http://img.shields.io/npm/dm/react-native-grid-list.svg"></a>
<img alt="npm version" src="https://travis-ci.org/gusgard/react-native-grid-list.svg?branch=master">
</p>

## Setup
## Installation

Run `yarn install`
```
yarn add react-native-grid-list
```

## Start
or

Run `yarn start`
```
npm install react-native-grid-list --save
```

## Simulator
## Example

For an Android device `yarn android`
```js
import React, { Component } from 'react';
import {
StyleSheet,
Image,
} from 'react-native';

For an iOS device `yarn ios`
import GridList from 'react-native-grid-list';

![Demo](./demo.gif)
const items = [
{ thumbnail: { uri:'http://lorempixel.com/640/480/animals'} },
{ thumbnail: {uri: 'https://facebook.github.io/react-native/img/favicon.png'} },
{ thumbnail: {uri: 'http://lorempixel.com/640/480/nature'} },
];

export default class ExampleGrid extends Component {

renderItem = ({ item, index }) => (
<Image
style={styles.image}
source={item.thumbnail}
/>
)

render() {
return (
<GridList
renderItem={this.renderItem}
data={items}
numColumns={3}
/>
);
}
}

const styles = StyleSheet.create({
...
});
```

### Expo

[Example QR](https://snack.expo.io/girdList)

## Props

| Prop | Default | Type | Description |
| :--------- | :--------: | :------: | :----------------------------------------- |
| numColumns | 3 | `number` | Number of elements in a row |
| data | _required_ | `array` | Data used when render items |
| renderItem | _required_ | `func` | Function that render each item of the grid |

## Author

Expand Down
5 changes: 1 addition & 4 deletions example/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';

import ListGrid from 'react-native-grid-list';

const logo = {
Expand All @@ -16,7 +15,7 @@ export default class App extends Component {
render() {
return (
<View style={styles.container}>
<ListGrid items={items} />
<ListGrid data={items} />
</View>
);
}
Expand All @@ -25,8 +24,6 @@ export default class App extends Component {
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});
11 changes: 10 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
"ios": "react-native run-ios --simulator='iPhone 6'",
"postinstall":
"rm -rf node_modules/react-native-grid-list/node_modules/react-native",
"start": "node node_modules/react-native/local-cli/cli.js start"
"watch": "node ./scripts/watch-and-copy.js",
"start": "concurrently 'npm run watch' 'npm run start-rn'",
"start-rn": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "16.0.0",
"react-native": "0.50.3",
"react-native-grid-list": "file:../"
},
"devDependencies": {
"concurrently": "^2.2.0",
"fs-extra": "^0.30.0",
"minimatch": "^3.0.2",
"node-watch": "^0.4.0",
"rimraf": "^2.5.4"
}
}
34 changes: 34 additions & 0 deletions example/scripts/watch-and-copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const path = require('path');
const fs = require('fs-extra');
const watch = require('node-watch');
const rimraf = require('rimraf');
const minimatch = require('minimatch');

function copyAndWatch(source, destination, fileGlob) {
console.log(`Cleaning "${destination}"`);
rimraf(destination, () => {
console.log(`Copying "${source}" to "${destination}"`);
fs.copy(source, destination, err => {
if (err) console.error(err);
});

console.log(`Watching "${source}"`);
watch(source, filename => {
const localPath = filename.split(source).pop();
if (matchesFile(localPath, fileGlob)) {
const destinationPath = `${destination}${localPath}`;
console.log(`Copying "${filename}" to "${destinationPath}"`);
fs.copy(filename, destinationPath, err => {
if (err) console.error(err);
});
}
});
});
}

function matchesFile(filename, fileGlob) {
if (fileGlob == null) return true;
return minimatch(path.basename(filename), fileGlob);
}

copyAndWatch('../src', 'node_modules/react-native-grid-list/src');
92 changes: 89 additions & 3 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ ansi-escapes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92"

ansi-regex@^0.2.0, ansi-regex@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-0.2.1.tgz#0d8e946967a3d8143f93e24e298525fc1b2235f9"

ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
Expand All @@ -52,6 +56,10 @@ ansi-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"

ansi-styles@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.1.0.tgz#eaecbf66cd706882760b2f4691582b8f55d7a7de"

ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
Expand Down Expand Up @@ -755,6 +763,10 @@ block-stream@*:
dependencies:
inherits "~2.0.0"

[email protected]:
version "2.9.6"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.9.6.tgz#1fc3a6b1685267dc121b5ec89b32ce069d81ab7d"

body-parser@~1.13.3:
version "1.13.3"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.13.3.tgz#c08cf330c3358e151016a05746f13f029c97fa97"
Expand Down Expand Up @@ -841,6 +853,16 @@ caseless@~0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"

[email protected]:
version "0.5.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.5.1.tgz#663b3a648b68b55d04690d49167aa837858f2174"
dependencies:
ansi-styles "^1.1.0"
escape-string-regexp "^1.0.0"
has-ansi "^0.1.0"
strip-ansi "^0.3.0"
supports-color "^0.2.0"

chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
Expand Down Expand Up @@ -913,6 +935,10 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
dependencies:
delayed-stream "~1.0.0"

[email protected]:
version "2.6.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.6.0.tgz#9df7e52fb2a0cb0fb89058ee80c3104225f37e1d"

commander@^2.9.0, commander@~2.11.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
Expand Down Expand Up @@ -946,6 +972,18 @@ concat-stream@^1.6.0:
readable-stream "^2.2.2"
typedarray "^0.0.6"

concurrently@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-2.2.0.tgz#bad248e0bb129fb1621768903a6311d45d56895a"
dependencies:
bluebird "2.9.6"
chalk "0.5.1"
commander "2.6.0"
cross-spawn "^0.2.9"
lodash "^4.5.1"
moment "^2.11.2"
rx "2.3.24"

connect-timeout@~1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/connect-timeout/-/connect-timeout-1.6.2.tgz#de9a5ec61e33a12b6edaab7b5f062e98c599b88e"
Expand Down Expand Up @@ -1050,6 +1088,12 @@ create-react-class@^15.5.2:
loose-envify "^1.3.1"
object-assign "^4.1.1"

cross-spawn@^0.2.9:
version "0.2.9"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-0.2.9.tgz#bd67f96c07efb6303b7fe94c1e979f88478e0a39"
dependencies:
lru-cache "^2.5.0"

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -1214,7 +1258,7 @@ escape-html@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"

escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
escape-string-regexp@^1.0.0, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

Expand Down Expand Up @@ -1411,6 +1455,16 @@ [email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.3.0.tgz#651f838e22424e7566de161d8358caa199f83d4f"

fs-extra@^0.30.0:
version "0.30.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.30.0.tgz#f233ffcc08d4da7d432daa449776989db1df93f0"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^2.1.0"
klaw "^1.0.0"
path-is-absolute "^1.0.0"
rimraf "^2.2.8"

fs-extra@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950"
Expand Down Expand Up @@ -1584,6 +1638,12 @@ har-validator@~5.0.3:
ajv "^5.1.0"
har-schema "^2.0.0"

has-ansi@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-0.1.0.tgz#84f265aae8c0e6a88a12d7022894b7568894c62e"
dependencies:
ansi-regex "^0.2.0"

has-ansi@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
Expand Down Expand Up @@ -2062,7 +2122,7 @@ lodash@^3.5.0:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

lodash@^4.14.0, lodash@^4.16.6, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.6.1:
lodash@^4.14.0, lodash@^4.16.6, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.5.1, lodash@^4.6.1:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

Expand All @@ -2072,6 +2132,10 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
dependencies:
js-tokens "^3.0.0"

lru-cache@^2.5.0:
version "2.7.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"

lru-cache@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.1.tgz#622e32e82488b49279114a4f9ecf45e7cd6bba55"
Expand Down Expand Up @@ -2247,6 +2311,10 @@ minimist@~0.0.1:
dependencies:
minimist "0.0.8"

moment@^2.11.2:
version "2.19.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.19.2.tgz#8a7f774c95a64550b4c7ebd496683908f9419dbe"

morgan@~1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.6.1.tgz#5fd818398c6819cba28a7cd6664f292fe1c0bbf2"
Expand Down Expand Up @@ -2334,6 +2402,10 @@ node-pre-gyp@^0.6.39:
tar "^2.2.1"
tar-pack "^3.4.0"

node-watch@^0.4.0:
version "0.4.1"
resolved "https://registry.yarnpkg.com/node-watch/-/node-watch-0.4.1.tgz#d0947d54a995f91135db4056b68722c6d7c322ad"

nopt@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d"
Expand Down Expand Up @@ -2931,7 +3003,7 @@ restore-cursor@^2.0.0:
onetime "^2.0.0"
signal-exit "^3.0.2"

rimraf@2, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
version "2.6.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
dependencies:
Expand Down Expand Up @@ -2961,6 +3033,10 @@ rx-lite@*, rx-lite@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444"

[email protected]:
version "2.3.24"
resolved "https://registry.yarnpkg.com/rx/-/rx-2.3.24.tgz#14f950a4217d7e35daa71bbcbe58eff68ea4b2b7"

safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
Expand Down Expand Up @@ -3197,6 +3273,12 @@ stringstream@~0.0.4, stringstream@~0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"

strip-ansi@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.3.0.tgz#25f48ea22ca79187f3174a4db8759347bb126220"
dependencies:
ansi-regex "^0.2.1"

strip-ansi@^3.0.0, strip-ansi@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
Expand All @@ -3221,6 +3303,10 @@ strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"

supports-color@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-0.2.0.tgz#d92de2694eb3f67323973d7ae3d8b55b4c22190a"

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
Expand Down
Loading

0 comments on commit 68cb30c

Please sign in to comment.