Skip to content

Commit 6ae9535

Browse files
authored
Feature/refactors (#4)
* add solidarity, upgrade packages and remove old code * add gif demo * update snapshots
1 parent 4f77c58 commit 6ae9535

File tree

10 files changed

+1394
-194
lines changed

10 files changed

+1394
-194
lines changed

.solidarity

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"$schema": "http://json.schemastore.org/solidaritySchema",
3+
"requirements": {
4+
"Node": [
5+
{
6+
"rule": "cli",
7+
"binary": "node",
8+
"semver": "8.9.1"
9+
}
10+
],
11+
"Watchman": [
12+
{
13+
"rule": "cli",
14+
"binary": "watchman",
15+
"error": "Please install watchman on this machine. Refer to the official Watchman installation instructions for additional help.",
16+
"platform": [
17+
"darwin",
18+
"linux"
19+
]
20+
}
21+
],
22+
"React Native": [
23+
{
24+
"rule": "cli",
25+
"binary": "react-native",
26+
"semver": "0.50.3",
27+
"line": 2
28+
}
29+
],
30+
"Package JSON": [
31+
{
32+
"rule": "file",
33+
"location": "./package.json"
34+
}
35+
],
36+
"NPM": [
37+
{
38+
"rule": "cli",
39+
"binary": "npm",
40+
"semver": "5.5.1"
41+
}
42+
],
43+
"Yarn": [
44+
{
45+
"rule": "cli",
46+
"binary": "yarn",
47+
"version": "--version",
48+
"semver": "1.3.2"
49+
}
50+
],
51+
"Android": [
52+
{
53+
"rule": "env",
54+
"variable": "ANDROID_HOME",
55+
"error": "The ANDROID_HOME environment variable must be set to your local SDK. Refer to getting started docs for help."
56+
}
57+
],
58+
"Xcode": [
59+
{
60+
"rule": "cli",
61+
"binary": "xcodebuild",
62+
"semver": "9.1",
63+
"platform": "darwin"
64+
},
65+
{
66+
"rule": "cli",
67+
"binary": "xcrun",
68+
"semver": "35",
69+
"platform": "darwin"
70+
}
71+
]
72+
}
73+
}

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![Travis](https://travis-ci.org/gusgard/rn-graphql-example.svg)
2+
13
# Installation
24

35
Example with graphql api
@@ -6,10 +8,10 @@ Example with graphql api
68

79
Run `yarn install`
810

9-
1011
## Start
1112

1213
Run `yarn start`
14+
1315
Run `yarn api`
1416

1517
## Simulator
@@ -18,7 +20,8 @@ For an Android device `yarn android`
1820

1921
For an iOS device `yarn ios`
2022

21-
![Demo](./demo.gif.)
23+
![Demo](./demo.gif)
2224

2325
## Author
26+
2427
Gustavo Gard

db.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
const Faker = require('faker');
22

3+
const newImage = {
4+
0: Faker.image.business,
5+
1: Faker.image.cats,
6+
2: Faker.image.city,
7+
3: Faker.image.food,
8+
4: Faker.image.nightlife,
9+
5: Faker.image.fashion,
10+
6: Faker.image.people,
11+
7: Faker.image.nature,
12+
8: Faker.image.animals,
13+
9: Faker.image.imageUrl,
14+
};
15+
const getNewImage = index =>
16+
newImage[index % (Object.keys(newImage).length - 1)]();
17+
318
const user = {
419
description: Faker.lorem.paragraphs(),
520
id: 1234,
621
name: Faker.name.findName(),
722
thumbnail: Faker.image.avatar(),
823
};
924

10-
const photo = () => ({
25+
const photo = index => ({
1126
id: Faker.random.uuid(),
12-
thumbnail: Faker.image.imageUrl(),
27+
thumbnail: getNewImage(index),
1328
user_id: user.id,
1429
});
1530

16-
// business
17-
// cats
18-
// city
19-
// food
20-
// nightlife
21-
// fashion
22-
// people
23-
// nature
24-
25-
const pop = () => ({
31+
const popular = index => ({
2632
id: Faker.random.uuid(),
27-
thumbnail: Faker.image.animals(),
33+
thumbnail: getNewImage(index),
2834
});
2935

3036
const MAX_PHOTOS = Math.round(Math.random() * 10) + 1;
31-
const profiles = Array.from(Array(MAX_PHOTOS)).map(() => photo());
37+
const profiles = Array.from(Array(MAX_PHOTOS)).map((_, index) => photo(index));
3238

33-
const MAX_POPULAR = Math.round(Math.random() * 30) + 1;
34-
const populars = Array.from(Array(MAX_POPULAR)).map(() => pop());
39+
const MAX_POPULAR = Math.round(Math.random() * 100) + 1;
40+
const populars = Array.from(Array(MAX_POPULAR)).map((_, index) =>
41+
popular(index),
42+
);
3543

3644
module.exports = {
3745
profiles,

demo.gif

3.57 MB
Loading

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"start": "node node_modules/react-native/local-cli/cli.js start",
1212
"api": "json-graphql-server db.js",
1313
"test": "jest",
14+
"check-env": "yarn solidarity",
1415
"test-watch": "jest --watch"
1516
},
1617
"dependencies": {
@@ -57,14 +58,14 @@
5758
"prettier": "^1.3.1",
5859
"prettier-eslint": "^8.2.1",
5960
"react-dom": "^16.0.0",
60-
"redux-mock-store": "^1.3.0"
61+
"redux-mock-store": "^1.3.0",
62+
"solidarity": "^1.0.0",
63+
"solidarity-react-native": "^1.0.0"
6164
},
6265
"jest": {
6366
"preset": "react-native",
6467
"setupTestFrameworkScriptFile": "./enzyme.js",
65-
"snapshotSerializers": [
66-
"./node_modules/enzyme-to-json/serializer"
67-
]
68+
"snapshotSerializers": ["./node_modules/enzyme-to-json/serializer"]
6869
},
6970
"pre-commit": {
7071
"run": "lint"

src/apolloClient.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ApolloClient, createNetworkInterface } from 'react-apollo';
22

3+
import { API_URL } from '@environment';
4+
35
export default new ApolloClient({
46
networkInterface: createNetworkInterface({
5-
uri: 'http://localhost:3000',
7+
uri: API_URL,
68
}),
79
});

src/environment/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ if (isDev) {
88
GLOBAL.XMLHttpRequest =
99
GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest;
1010
}
11+
12+
const urls = {
13+
development: 'http://localhost:3000',
14+
test: 'http://localhost:3000',
15+
production: 'http://localhost:3000',
16+
};
17+
18+
export const API_URL = urls[env];
Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,65 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`renders Description without Read more text 1`] = `
4-
<TouchableOpacity
5-
activeOpacity={0.2}
6-
onPress={[Function]}
4+
<Text
5+
accessible={true}
6+
allowFontScaling={true}
7+
ellipsizeMode="tail"
8+
numberOfLines={4}
79
>
810
<Text
911
accessible={true}
1012
allowFontScaling={true}
1113
ellipsizeMode="tail"
12-
numberOfLines={0}
14+
key="0"
1315
>
14-
<Text
15-
accessible={true}
16-
allowFontScaling={true}
17-
ellipsizeMode="tail"
18-
key="0"
19-
>
20-
Motivation to become the best version of you!
21-
</Text>
22-
<Text
23-
accessible={true}
24-
allowFontScaling={true}
25-
ellipsizeMode="tail"
26-
key="1"
27-
style={
28-
Object {
29-
"color": "rgb(15, 45, 90)",
30-
"fontWeight": "bold",
31-
}
16+
Motivation to become the best version of you!
17+
</Text>
18+
<Text
19+
accessible={true}
20+
allowFontScaling={true}
21+
ellipsizeMode="tail"
22+
key="1"
23+
style={
24+
Object {
25+
"color": "rgb(15, 45, 90)",
26+
"fontWeight": "bold",
3227
}
33-
>
34-
#Whitebear
35-
</Text>
28+
}
29+
>
30+
#Whitebear
3631
</Text>
37-
</TouchableOpacity>
32+
</Text>
3833
`;
3934

4035
exports[`renders correctly 1`] = `
41-
<TouchableOpacity
42-
activeOpacity={0.2}
43-
onPress={[Function]}
36+
<Text
37+
accessible={true}
38+
allowFontScaling={true}
39+
ellipsizeMode="tail"
40+
numberOfLines={4}
4441
>
4542
<Text
4643
accessible={true}
4744
allowFontScaling={true}
4845
ellipsizeMode="tail"
49-
numberOfLines={4}
46+
key="0"
5047
>
51-
<Text
52-
accessible={true}
53-
allowFontScaling={true}
54-
ellipsizeMode="tail"
55-
key="0"
56-
>
57-
Motivation to become the best version of you!
58-
</Text>
59-
<Text
60-
accessible={true}
61-
allowFontScaling={true}
62-
ellipsizeMode="tail"
63-
key="1"
64-
style={
65-
Object {
66-
"color": "rgb(15, 45, 90)",
67-
"fontWeight": "bold",
68-
}
48+
Motivation to become the best version of you!
49+
</Text>
50+
<Text
51+
accessible={true}
52+
allowFontScaling={true}
53+
ellipsizeMode="tail"
54+
key="1"
55+
style={
56+
Object {
57+
"color": "rgb(15, 45, 90)",
58+
"fontWeight": "bold",
6959
}
70-
>
71-
#Whitebear
72-
</Text>
60+
}
61+
>
62+
#Whitebear
7363
</Text>
74-
</TouchableOpacity>
64+
</Text>
7565
`;
Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { PureComponent } from 'react';
2-
import { Text, TouchableOpacity } from 'react-native';
2+
import { Text } from 'react-native';
33
import PropTypes from 'prop-types';
44

55
import styles from './styles';
@@ -11,32 +11,21 @@ export default class Description extends PureComponent {
1111
texts: PropTypes.array.isRequired,
1212
};
1313

14-
state = {
15-
readMore: true,
16-
};
17-
18-
toggleReadMore = () => {
19-
this.setState({ readMore: !this.state.readMore });
20-
};
21-
2214
render() {
2315
const { texts } = this.props;
24-
const { readMore } = this.state;
2516
return (
26-
<TouchableOpacity onPress={this.toggleReadMore}>
27-
<Text numberOfLines={readMore ? MAX_LINES : 0} style={styles.texts}>
28-
{texts.map(
29-
(text, index) =>
30-
text.highlighted ? (
31-
<Text key={index} style={styles.highlighted}>
32-
{text.value}
33-
</Text>
34-
) : (
35-
<Text key={index}>{text.value}</Text>
36-
),
37-
)}
38-
</Text>
39-
</TouchableOpacity>
17+
<Text numberOfLines={MAX_LINES} style={styles.texts}>
18+
{texts.map(
19+
(text, index) =>
20+
text.highlighted ? (
21+
<Text key={index} style={styles.highlighted}>
22+
{text.value}
23+
</Text>
24+
) : (
25+
<Text key={index}>{text.value}</Text>
26+
),
27+
)}
28+
</Text>
4029
);
4130
}
4231
}

0 commit comments

Comments
 (0)