Skip to content

Commit 84ff99c

Browse files
authored
Feature/improve theme (#171)
1 parent 18df9bd commit 84ff99c

File tree

5 files changed

+93
-34
lines changed

5 files changed

+93
-34
lines changed

template/src/Containers/Example/Index.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import React, { useState } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
3-
import { View, ActivityIndicator, Text, TextInput, Button } from 'react-native'
3+
import {
4+
View,
5+
ActivityIndicator,
6+
Text,
7+
TextInput,
8+
TouchableOpacity,
9+
} from 'react-native'
410
import { Brand } from '@/Components'
511
import { useTheme } from '@/Theme'
612
import FetchOne from '@/Store/User/FetchOne'
@@ -37,7 +43,9 @@ const IndexExampleContainer = () => {
3743
{fetchOneUserError ? (
3844
<Text style={Fonts.textRegular}>{fetchOneUserError.message}</Text>
3945
) : (
40-
<Text style={Fonts.textRegular}>{t('example.helloUser', { name: user.name })}</Text>
46+
<Text style={Fonts.textRegular}>
47+
{t('example.helloUser', { name: user.name })}
48+
</Text>
4149
)}
4250
</View>
4351
<View
@@ -49,7 +57,7 @@ const IndexExampleContainer = () => {
4957
Common.backgroundPrimary,
5058
]}
5159
>
52-
<Text style={[Layout.fill, Fonts.textCenter]}>
60+
<Text style={[Layout.fill, Fonts.textCenter, Fonts.textSmall]}>
5361
{t('example.labels.userId')}
5462
</Text>
5563
<TextInput
@@ -62,10 +70,26 @@ const IndexExampleContainer = () => {
6270
style={[Layout.fill, Common.textInput]}
6371
/>
6472
</View>
65-
<Text style={Fonts.textRegular}>DarkMode :</Text>
66-
<Button onPress={() => changeTheme({ darkMode: null })} title="Auto" />
67-
<Button onPress={() => changeTheme({ darkMode: true })} title="Dark" />
68-
<Button onPress={() => changeTheme({ darkMode: false })} title="Light" />
73+
<Text style={[Fonts.textRegular, Gutters.smallBMargin]}>DarkMode :</Text>
74+
75+
<TouchableOpacity
76+
style={[Common.button.rounded, Gutters.regularBMargin]}
77+
onPress={() => changeTheme({ darkMode: null })}
78+
>
79+
<Text style={Fonts.textRegular}>Auto</Text>
80+
</TouchableOpacity>
81+
<TouchableOpacity
82+
style={[Common.button.outlineRounded, Gutters.regularBMargin]}
83+
onPress={() => changeTheme({ darkMode: true })}
84+
>
85+
<Text style={Fonts.textRegular}>Dark</Text>
86+
</TouchableOpacity>
87+
<TouchableOpacity
88+
style={[Common.button.outline, Gutters.regularBMargin]}
89+
onPress={() => changeTheme({ darkMode: false })}
90+
>
91+
<Text style={Fonts.textRegular}>Light</Text>
92+
</TouchableOpacity>
6993
</View>
7094
)
7195
}

template/src/Theme/Common.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44
* Use it to define generic component styles (e.g. the default text styles, default button styles...).
55
*/
66
import { StyleSheet } from 'react-native'
7-
7+
import buttonStyles from './components/Buttons'
88
/**
99
*
1010
* @param Theme can be spread like {Colors, NavigationColors, Gutters, Layout, Common, ...args}
1111
* @return {*}
1212
*/
13-
export default function ({ Colors }) {
14-
return StyleSheet.create({
15-
button: {
16-
backgroundColor: Colors.primary,
17-
},
18-
backgroundPrimary: {
19-
backgroundColor: Colors.primary,
20-
},
21-
backgroundReset: {
22-
backgroundColor: Colors.transparent,
23-
},
24-
textInput: {
25-
borderWidth: 1,
26-
borderColor: Colors.text,
27-
backgroundColor: Colors.inputBackground,
28-
color: Colors.text,
29-
minHeight: 50,
30-
textAlign: 'center',
31-
marginTop: 10,
32-
marginBottom: 10,
33-
},
34-
})
13+
export default function ({ Colors, ...args }) {
14+
return {
15+
button: buttonStyles({ Colors, ...args }),
16+
...StyleSheet.create({
17+
backgroundPrimary: {
18+
backgroundColor: Colors.primary,
19+
},
20+
backgroundReset: {
21+
backgroundColor: Colors.transparent,
22+
},
23+
textInput: {
24+
borderWidth: 1,
25+
borderColor: Colors.text,
26+
backgroundColor: Colors.inputBackground,
27+
color: Colors.text,
28+
minHeight: 50,
29+
textAlign: 'center',
30+
marginTop: 10,
31+
marginBottom: 10,
32+
},
33+
}),
34+
}
3535
}

template/src/Theme/Variables.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export const NavigationColors = {
2727
* FontSize
2828
*/
2929
export const FontSize = {
30-
small: 12,
31-
regular: 14,
32-
large: 18,
30+
small: 16,
31+
regular: 20,
32+
large: 40,
3333
}
3434

3535
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { StyleSheet } from 'react-native'
2+
3+
export default function ({ Colors, Gutters, Layout }) {
4+
const base = {
5+
...Layout.center,
6+
...Gutters.largeHPadding,
7+
height: 40,
8+
backgroundColor: Colors.primary,
9+
}
10+
const rounded = {
11+
...base,
12+
borderRadius: 20,
13+
}
14+
15+
return StyleSheet.create({
16+
base,
17+
rounded,
18+
outline: {
19+
...base,
20+
backgroundColor: Colors.transparent,
21+
borderWidth: 2,
22+
borderColor: Colors.primary,
23+
},
24+
outlineRounded: {
25+
...rounded,
26+
backgroundColor: Colors.transparent,
27+
borderWidth: 2,
28+
borderColor: Colors.primary,
29+
},
30+
})
31+
}

template/src/Theme/hooks/useTheme.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ export default function () {
3535
const baseTheme = {
3636
Fonts: Fonts(themeVariables),
3737
Gutters: Gutters(themeVariables),
38-
Common: Common(themeVariables),
3938
Images: Images(themeVariables),
4039
Layout: Layout(themeVariables),
40+
Common: Common({
41+
...themeVariables,
42+
Layout: Layout(themeVariables),
43+
Gutters: Gutters(themeVariables),
44+
}),
4145
...themeVariables,
4246
}
4347

0 commit comments

Comments
 (0)