Skip to content

Commit a05d438

Browse files
committed
first commit
0 parents  commit a05d438

File tree

5 files changed

+225
-0
lines changed

5 files changed

+225
-0
lines changed

.gitignore

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+

index.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, { Component } from "react";
2+
import { StyleSheet, View, ListView, Dimensions } from "react-native";
3+
import PropTypes from "prop-types";
4+
5+
const { width } = Dimensions.get("window");
6+
7+
export default (Tiles = (
8+
{ style = {}, tilesPerRow = 3, dataSource, renderItem }
9+
) => {
10+
const tileDimensions = calcTileDimensions(width, tilesPerRow);
11+
return (
12+
<View style={{ flex: 1 }}>
13+
<ListView
14+
contentContainerStyle={[style || {}, styles.list]}
15+
dataSource={dataSource}
16+
renderRow={i => {
17+
const Hoc = MakeHOCItem({
18+
...tileDimensions
19+
})(renderItem);
20+
return <Hoc itemData={i} />;
21+
}}
22+
/>
23+
</View>
24+
);
25+
});
26+
27+
Tiles.propTypes = {
28+
style: PropTypes.object,
29+
tilesPerRow: PropTypes.number,
30+
renderItem: PropTypes.func.isRequired,
31+
dataSource: PropTypes.instanceOf(ListView.DataSource).isRequired
32+
};
33+
34+
const MakeHOCItem = ({ size, margin }) =>
35+
Comp =>
36+
({ itemData }) => {
37+
return (
38+
<View style={{ width: size, height: size, marginHorizontal: margin }}>
39+
{Comp(itemData, size)}
40+
</View>
41+
);
42+
};
43+
44+
const calcTileDimensions = (deviceWidth, tpr) => {
45+
const margin = deviceWidth / (tpr * 10);
46+
const size = (deviceWidth - margin * (tpr * 2)) / tpr;
47+
return { size, margin };
48+
};
49+
50+
const styles = StyleSheet.create({
51+
list: {
52+
justifyContent: "flex-start",
53+
flexDirection: "row",
54+
flexWrap: "wrap"
55+
}
56+
});

package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "react-native-tiles",
3+
"version": "1.0.0",
4+
"description": "A React-Native component to render square tiles",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"react-native"
11+
],
12+
"author": "Emilio Srougo",
13+
"license": "ISC",
14+
"peerDependencies": {
15+
"react": "^15.5.3",
16+
"react-native": "^0.43.2"
17+
},
18+
"dependencies": {
19+
"prop-types": "^15.5.6"
20+
}
21+
}

readme.md

Whitespace-only changes.

yarn.lock

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
asap@~2.0.3:
6+
version "2.0.5"
7+
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.5.tgz#522765b50c3510490e52d7dcfe085ef9ba96958f"
8+
9+
core-js@^1.0.0:
10+
version "1.2.7"
11+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
12+
13+
encoding@^0.1.11:
14+
version "0.1.12"
15+
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
16+
dependencies:
17+
iconv-lite "~0.4.13"
18+
19+
fbjs@^0.8.9:
20+
version "0.8.12"
21+
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.12.tgz#10b5d92f76d45575fd63a217d4ea02bea2f8ed04"
22+
dependencies:
23+
core-js "^1.0.0"
24+
isomorphic-fetch "^2.1.1"
25+
loose-envify "^1.0.0"
26+
object-assign "^4.1.0"
27+
promise "^7.1.1"
28+
setimmediate "^1.0.5"
29+
ua-parser-js "^0.7.9"
30+
31+
iconv-lite@~0.4.13:
32+
version "0.4.15"
33+
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.15.tgz#fe265a218ac6a57cfe854927e9d04c19825eddeb"
34+
35+
is-stream@^1.0.1:
36+
version "1.1.0"
37+
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
38+
39+
isomorphic-fetch@^2.1.1:
40+
version "2.2.1"
41+
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
42+
dependencies:
43+
node-fetch "^1.0.1"
44+
whatwg-fetch ">=0.10.0"
45+
46+
js-tokens@^3.0.0:
47+
version "3.0.1"
48+
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"
49+
50+
loose-envify@^1.0.0:
51+
version "1.3.1"
52+
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
53+
dependencies:
54+
js-tokens "^3.0.0"
55+
56+
node-fetch@^1.0.1:
57+
version "1.6.3"
58+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04"
59+
dependencies:
60+
encoding "^0.1.11"
61+
is-stream "^1.0.1"
62+
63+
object-assign@^4.1.0:
64+
version "4.1.1"
65+
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
66+
67+
promise@^7.1.1:
68+
version "7.1.1"
69+
resolved "https://registry.yarnpkg.com/promise/-/promise-7.1.1.tgz#489654c692616b8aa55b0724fa809bb7db49c5bf"
70+
dependencies:
71+
asap "~2.0.3"
72+
73+
prop-types@^15.5.6:
74+
version "15.5.6"
75+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.6.tgz#797a915b1714b645ebb7c5d6cc690346205bd2aa"
76+
dependencies:
77+
fbjs "^0.8.9"
78+
79+
setimmediate@^1.0.5:
80+
version "1.0.5"
81+
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
82+
83+
ua-parser-js@^0.7.9:
84+
version "0.7.12"
85+
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"
86+
87+
whatwg-fetch@>=0.10.0:
88+
version "1.1.1"
89+
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-1.1.1.tgz#ac3c9d39f320c6dce5339969d054ef43dd333319"

0 commit comments

Comments
 (0)