Skip to content

Commit

Permalink
Fix thecodingmachine#6 Add a App/Theme directory for storing the ba…
Browse files Browse the repository at this point in the history
…se application styles
  • Loading branch information
Matthieu Napoli committed Aug 13, 2018
1 parent cc96a1d commit 5203b8e
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 13 deletions.
27 changes: 14 additions & 13 deletions App/Containers/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { connect } from 'react-redux'
import { PropTypes } from 'prop-types'
import ExampleActions from 'App/Stores/Example/Actions'
import { isHot } from 'App/Stores/Example/Selectors'
import Fonts from 'App/Theme/Fonts'
import ApplicationStyles from 'App/Theme/ApplicationStyles'

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu',
ios: 'Press Cmd+R to reload,\nCmd+D or shake for dev menu.',
android: 'Double tap R on your keyboard to reload,\nShake or press menu button for dev menu.',
})

class HomeScreen extends React.Component {
Expand All @@ -23,12 +25,12 @@ class HomeScreen extends React.Component {

return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.title}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
<Text style={styles.instructions}>{instructions}</Text>
<Text style={styles.instructions}>The weather temperature is: {temperature}</Text>
<Text style={styles.instructions}>{this.props.isHot ? "It's pretty hot!" : ''}</Text>
<Text style={styles.instructions}>{this.props.temperatureErrorMessage}</Text>
<Text style={styles.text}>{instructions}</Text>
<Text style={styles.text}>The weather temperature is: {temperature}</Text>
<Text style={styles.text}>{this.props.isHot ? "It's pretty hot!" : ''}</Text>
<Text style={styles.text}>{this.props.temperatureErrorMessage}</Text>
<Button onPress={this.props.fetchTemperature} title="Refresh" />
</View>
)
Expand All @@ -37,16 +39,15 @@ class HomeScreen extends React.Component {

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
...ApplicationStyles.screen.container,
},
welcome: {
fontSize: 20,
title: {
...Fonts.style.h1,
textAlign: 'center',
margin: 10,
},
instructions: {
text: {
...Fonts.style.normal,
textAlign: 'center',
marginBottom: 5,
},
Expand Down
1 change: 1 addition & 0 deletions App/Images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains the application's images.
39 changes: 39 additions & 0 deletions App/Theme/ApplicationStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Fonts from './Fonts'
import Metrics from './Metrics'
import Colors from './Colors'

const ApplicationStyles = {
screen: {
mainContainer: {
flex: 1,
backgroundColor: Colors.transparent,
},
container: {
flex: 1,
paddingTop: Metrics.baseMargin,
backgroundColor: Colors.transparent,
},
section: {
margin: Metrics.section,
padding: Metrics.baseMargin,
},
sectionText: {
...Fonts.style.normal,
paddingVertical: Metrics.doubleMargin,
marginVertical: Metrics.smallMargin,
textAlign: 'center',
},
subtitle: {
padding: Metrics.smallMargin,
marginBottom: Metrics.smallMargin,
marginHorizontal: Metrics.smallMargin,
},
titleText: {
...Fonts.style.h2,
fontSize: 14,
color: Colors.text,
},
},
}

export default ApplicationStyles
9 changes: 9 additions & 0 deletions App/Theme/Colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const colors = {
transparent: 'rgba(0,0,0,0)',
text: '#212529',
primary: '#007bff',
success: '#28a745',
error: '#dc3545',
}

export default colors
53 changes: 53 additions & 0 deletions App/Theme/Fonts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const type = {
base: 'inherit',
}

const size = {
h1: 38,
h2: 34,
h3: 30,
h4: 26,
h5: 20,
h6: 19,
input: 18,
regular: 17,
medium: 14,
small: 12,
}

const style = {
h1: {
fontFamily: type.base,
fontSize: size.h1,
},
h2: {
fontFamily: type.base,
fontSize: size.h2,
},
h3: {
fontFamily: type.base,
fontSize: size.h3,
},
h4: {
fontFamily: type.base,
fontSize: size.h4,
},
h5: {
fontFamily: type.base,
fontSize: size.h5,
},
h6: {
fontFamily: type.base,
fontSize: size.h6,
},
normal: {
fontFamily: type.base,
fontSize: size.regular,
},
}

export default {
type,
size,
style,
}
8 changes: 8 additions & 0 deletions App/Theme/Images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Images should be stored in the `App/Images` directory and referenced using variables defined here.
*/
const Images = {
// logo: require('../Images/logo.png'),
}

export default Images
31 changes: 31 additions & 0 deletions App/Theme/Metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Dimensions, Platform } from 'react-native'

const { width, height } = Dimensions.get('window')

const metrics = {
marginHorizontal: 10,
marginVertical: 10,
baseMargin: 10,
doubleMargin: 20,
smallMargin: 5,
horizontalLineHeight: 1,
screenWidth: width < height ? width : height,
screenHeight: width < height ? height : width,
navBarHeight: Platform.OS === 'ios' ? 64 : 54,
buttonRadius: 4,
icons: {
tiny: 15,
small: 20,
medium: 30,
large: 45,
xl: 50,
},
images: {
small: 20,
medium: 40,
large: 60,
logo: 200,
},
}

export default metrics
1 change: 1 addition & 0 deletions App/Theme/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains the base for the application styles.
7 changes: 7 additions & 0 deletions App/Theme/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Colors from './Colors'
import Fonts from './Fonts'
import Metrics from './Metrics'
import Images from './Images'
import ApplicationStyles from './ApplicationStyles'

export { Colors, Fonts, Images, Metrics, ApplicationStyles }
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ This boilerplate contains:

- [`App/Components`](App/Components): presentational components
- [`App/Containers`](App/Containers): container components
- [`App/Images`](App/Images): images used by the application
- [`App/Stores`](App/Stores): redux [actions, reducers and stores](https://redux.js.org/basics)
- [`App/Sagas`](App/Sagas): redux sagas
- [`App/Theme`](App/Theme): base styles for the application

For more information on each directory, click the link and read the directory's README.

Expand Down

0 comments on commit 5203b8e

Please sign in to comment.