Skip to content

Commit

Permalink
Merge branch 'theme' into 'master'
Browse files Browse the repository at this point in the history
thecodingmachine#6 Ajout du dossier `Theme`

Closes thecodingmachine#6

See merge request tcm-projects/react-native-boilerplate!9
  • Loading branch information
aum-tcm committed Aug 20, 2018
2 parents cc96a1d + 2f176dd commit 3d884f9
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 76 deletions.
4 changes: 2 additions & 2 deletions App/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Component } from 'react'
import HomeScreen from 'App/Containers/HomeScreen'
import { Provider } from 'react-redux'
import { PersistGate } from 'redux-persist/lib/integration/react'
import createStore from 'App/Stores'
import ExampleScreen from './Containers/Example/ExampleScreen'

const { store, persistor } = createStore()

Expand All @@ -21,7 +21,7 @@ export default class App extends Component {
* @see https://github.com/rt2zz/redux-persist/blob/master/docs/PersistGate.md
*/}
<PersistGate loading={null} persistor={persistor}>
<HomeScreen />
<ExampleScreen />
</PersistGate>
</Provider>
)
Expand Down
58 changes: 58 additions & 0 deletions App/Containers/Example/ExampleScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react'
import { Platform, Text, View, Button } from 'react-native'
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 Style from './ExampleScreenStyle'

const instructions = Platform.select({
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 ExampleScreen extends React.Component {
componentDidMount() {
this.props.fetchTemperature()
}

render() {
let temperature = this.props.temperatureIsLoading ? '...' : this.props.temperature
if (temperature === null) {
temperature = '??'
}

return (
<View style={Style.container}>
<Text style={Style.title}>Welcome to React Native!</Text>
<Text style={Style.text}>To get started, edit App.js</Text>
<Text style={Style.text}>{instructions}</Text>
<Text style={Style.text}>The weather temperature is: {temperature}</Text>
<Text style={Style.text}>{this.props.isHot ? "It's pretty hot!" : ''}</Text>
<Text style={Style.text}>{this.props.temperatureErrorMessage}</Text>
<Button onPress={this.props.fetchTemperature} title="Refresh" />
</View>
)
}
}

ExampleScreen.propsTypes = {
temperature: PropTypes.number,
temperatureErrorMessage: PropTypes.string,
}

const mapStateToProps = (state) => ({
temperature: state.example.get('temperature'),
temperatureErrorMessage: state.example.get('temperatureErrorMessage'),
temperatureIsLoading: state.example.get('temperatureIsLoading'),
isHot: isHot(state),
})

const mapDispatchToProps = (dispatch) => ({
fetchTemperature: () => dispatch(ExampleActions.fetchTemperature()),
})

export default connect(
mapStateToProps,
mapDispatchToProps
)(ExampleScreen)
19 changes: 19 additions & 0 deletions App/Containers/Example/ExampleScreenStyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { StyleSheet } from 'react-native'
import Fonts from 'App/Theme/Fonts'
import ApplicationStyles from 'App/Theme/ApplicationStyles'

export default StyleSheet.create({
container: {
...ApplicationStyles.screen.container,
},
title: {
...Fonts.style.h1,
textAlign: 'center',
margin: 10,
},
text: {
...Fonts.style.normal,
textAlign: 'center',
marginBottom: 5,
},
})
74 changes: 0 additions & 74 deletions App/Containers/HomeScreen.js

This file was deleted.

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.
13 changes: 13 additions & 0 deletions App/Theme/ApplicationStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* This file defines the base application styles.
*
* Use it to define generic component styles (e.g. the default text styles, default button styles...).
*/

export default {
screen: {
container: {
flex: 1,
},
},
}
15 changes: 15 additions & 0 deletions App/Theme/Colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This file contains the application's colors.
*
* Define color here instead of duplicating them throughout the components.
* That allows to change them more easily later on.
*/

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

const size = {
h1: 38,
h2: 34,
h3: 30,
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,
},
normal: {
fontFamily: type.base,
fontSize: size.regular,
},
}

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

export default {
// logo: require('../Images/logo.png'),
}
10 changes: 10 additions & 0 deletions App/Theme/Metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file contains metric values that are global to the application.
*/

export default {
// Examples of metrics you can define:
// baseMargin: 10,
// largeMargin: 20,
// smallMargin: 5,
}
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 3d884f9

Please sign in to comment.