Skip to content

Commit 12984da

Browse files
JeremyDolleAurelGit
authored andcommitted
refactoring Theme and Components (#83)
* refactoring Theme and Components to use more Helpers and remove unnecessary styles
1 parent 1d20a82 commit 12984da

File tree

10 files changed

+51
-79
lines changed

10 files changed

+51
-79
lines changed

App/Containers/Example/ExampleScreen.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PropTypes } from 'prop-types'
55
import ExampleActions from 'App/Stores/Example/Actions'
66
import { liveInEurope } from 'App/Stores/Example/Selectors'
77
import Style from './ExampleScreenStyle'
8-
import { Images } from 'App/Theme'
8+
import { ApplicationStyles, Helpers, Images, Metrics } from 'App/Theme'
99

1010
/**
1111
* This is an example of a container component.
@@ -26,13 +26,20 @@ class ExampleScreen extends React.Component {
2626

2727
render() {
2828
return (
29-
<View style={Style.container}>
29+
<View
30+
style={[
31+
Helpers.fill,
32+
Helpers.rowMain,
33+
Metrics.mediumHorizontalMargin,
34+
Metrics.mediumVerticalMargin,
35+
]}
36+
>
3037
{this.props.userIsLoading ? (
3138
<ActivityIndicator size="large" color="#0000ff" />
3239
) : (
3340
<View>
3441
<View style={Style.logoContainer}>
35-
<Image style={Style.logo} source={Images.logo} resizeMode={'contain'} />
42+
<Image style={Helpers.fullSize} source={Images.logo} resizeMode={'contain'} />
3643
</View>
3744
<Text style={Style.text}>To get started, edit App.js</Text>
3845
<Text style={Style.instructions}>{instructions}</Text>
@@ -49,13 +56,17 @@ class ExampleScreen extends React.Component {
4956
</Text>
5057
</View>
5158
)}
52-
<Button onPress={() => this._fetchUser()} title="Refresh" />
59+
<Button
60+
style={ApplicationStyles.button}
61+
onPress={() => this._fetchUser()}
62+
title="Refresh"
63+
/>
5364
</View>
5465
)}
5566
</View>
5667
)
5768
}
58-
69+
5970
_fetchUser() {
6071
this.props.fetchUser()
6172
}
Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,32 @@
11
import { StyleSheet } from 'react-native'
2-
import Fonts from 'App/Theme/Fonts'
3-
import ApplicationStyles from 'App/Theme/ApplicationStyles'
2+
import { Helpers, Metrics, Fonts, Colors } from 'App/Theme'
43

54
export default StyleSheet.create({
6-
container: {
7-
...ApplicationStyles.screen.container,
8-
margin: 30,
9-
flex: 1,
10-
justifyContent: 'center',
11-
},
12-
title: {
13-
...Fonts.style.h2,
14-
textAlign: 'center',
15-
marginBottom: 10,
16-
},
17-
text: {
18-
...Fonts.style.normal,
5+
error: {
6+
...Fonts.normal,
7+
color: Colors.error,
8+
marginBottom: Metrics.tiny,
199
textAlign: 'center',
20-
marginBottom: 5,
2110
},
2211
instructions: {
23-
...Fonts.style.normal,
24-
textAlign: 'center',
25-
marginBottom: 5,
12+
...Fonts.normal,
2613
fontStyle: 'italic',
27-
},
28-
loading: {
29-
...Fonts.style.normal,
30-
textAlign: 'center',
31-
marginBottom: 5,
32-
},
33-
result: {
34-
...Fonts.style.normal,
14+
marginBottom: Metrics.tiny,
3515
textAlign: 'center',
36-
marginBottom: 5,
37-
},
38-
error: {
39-
...Fonts.style.normal,
40-
textAlign: 'center',
41-
marginBottom: 5,
42-
color: 'red',
4316
},
4417
logoContainer: {
45-
width: '100%',
18+
...Helpers.fullWidth,
4619
height: 300,
4720
marginBottom: 25,
4821
},
49-
logo: {
50-
width: '100%',
51-
height: '100%',
22+
result: {
23+
...Fonts.normal,
24+
marginBottom: Metrics.tiny,
25+
textAlign: 'center',
26+
},
27+
text: {
28+
...Fonts.normal,
29+
marginBottom: Metrics.tiny,
30+
textAlign: 'center',
5231
},
5332
})

App/Containers/Root/RootScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import React, { Component } from 'react'
22
import NavigationService from 'App/Services/NavigationService'
33
import AppNavigator from 'App/Navigators/AppNavigator'
44
import { View } from 'react-native'
5-
import styles from './RootScreenStyle'
65
import { connect } from 'react-redux'
76
import StartupActions from 'App/Stores/Startup/Actions'
87
import { PropTypes } from 'prop-types'
8+
import { Helpers } from 'App/Theme'
99

1010
class RootScreen extends Component {
1111
componentDidMount() {
@@ -15,7 +15,7 @@ class RootScreen extends Component {
1515

1616
render() {
1717
return (
18-
<View style={styles.container}>
18+
<View style={Helpers.fill}>
1919
<AppNavigator
2020
// Initialize the NavigationService (see https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html)
2121
ref={(navigatorRef) => {

App/Containers/Root/RootScreenStyle.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

App/Containers/SplashScreen/SplashScreen.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react'
22
import { Text, View } from 'react-native'
33
import styles from './SplashScreenStyle'
4+
import { Helpers } from 'App/Theme'
45

56
export default class SplashScreen extends React.Component {
67
render() {
78
return (
8-
<View style={styles.container}>
9-
<View style={styles.logo}>
9+
<View style={[Helpers.fillRowCenter, styles.container]}>
10+
<View style={[Helpers.center, styles.logo]}>
1011
{/* You will probably want to insert your logo here */}
1112
<Text>LOGO</Text>
1213
</View>
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { StyleSheet } from 'react-native'
2-
import Colors from 'App/Theme/Colors'
3-
import ApplicationStyles from 'App/Theme/ApplicationStyles'
2+
import { Colors } from 'App/Theme'
43

54
export default StyleSheet.create({
65
container: {
7-
...ApplicationStyles.screen.container,
8-
display: 'flex',
9-
justifyContent: 'center',
10-
alignItems: 'center',
116
backgroundColor: Colors.primary,
127
},
138
logo: {
14-
display: 'flex',
15-
justifyContent: 'center',
16-
alignItems: 'center',
9+
backgroundColor: Colors.white,
1710
height: 70,
1811
width: 70,
19-
backgroundColor: 'white',
2012
},
2113
})

App/Theme/ApplicationStyles.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
*
44
* Use it to define generic component styles (e.g. the default text styles, default button styles...).
55
*/
6+
import Colors from './Colors'
67

78
export default {
8-
screen: {
9-
container: {
10-
flex: 1,
11-
},
9+
button: {
10+
backgroundColor: Colors.primary,
1211
},
1312
}

App/Theme/Colors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
export default {
99
transparent: 'rgba(0,0,0,0)',
10-
//Example colors:
10+
// Example colors:
11+
white: '#ffffff',
1112
text: '#212529',
1213
primary: '#007bff',
1314
success: '#28a745',

App/Theme/Fonts.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { StyleSheet } from 'react-native'
2+
13
const size = {
24
h1: 38,
35
h2: 34,
@@ -8,7 +10,7 @@ const size = {
810
small: 12,
911
}
1012

11-
const style = {
13+
export default StyleSheet.create({
1214
h1: {
1315
fontSize: size.h1,
1416
},
@@ -21,9 +23,4 @@ const style = {
2123
normal: {
2224
fontSize: size.regular,
2325
},
24-
}
25-
26-
export default {
27-
size,
28-
style,
29-
}
26+
})

App/Theme/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Colors from './Colors'
22
import Fonts from './Fonts'
33
import Metrics from './Metrics'
44
import Images from './Images'
5-
import ApplicationStyles from './ApplicationStyles'
65
import Helpers from './Helpers'
6+
import ApplicationStyles from './ApplicationStyles'
77

8-
export { Colors, Fonts, Images, Metrics, ApplicationStyles, Helpers }
8+
export { Colors, Fonts, Images, Metrics, Helpers, ApplicationStyles }

0 commit comments

Comments
 (0)