|
1 | | -import React, {PureComponent} from 'react'; |
2 | | -import SafeAreaView from 'react-native-safe-area-view'; |
3 | | -import { DrawerNavigatorItems } from 'react-navigation-drawer'; |
4 | | -import { StyleSheet, Text } from 'react-native'; |
| 1 | +import React, { PureComponent } from 'react'; |
| 2 | +import { StyleSheet, View, Text, Switch } from 'react-native'; |
5 | 3 | import { |
6 | 4 | Container, Header, Content, HeaderBody, |
7 | | - HeaderRight,Footer, |
| 5 | + HeaderRight, Footer, |
8 | 6 | HeaderLeft, Button |
9 | 7 | } from '../../components/index'; |
10 | 8 | import { GlobalStyle } from '../../theme/global'; |
11 | 9 | import store from '../../store/configureStore'; |
12 | 10 | import * as loginTypes from '../login/types'; |
| 11 | +import { wrapTheme } from '../../theme/themeProvider'; |
| 12 | +import storageService from '../../utils/storageService'; |
| 13 | + |
| 14 | + |
| 15 | +class Sidemenu extends PureComponent { |
13 | 16 |
|
14 | | -export class SidemenuScreen extends PureComponent { |
15 | 17 | constructor(props) { |
16 | 18 | super(props) |
17 | | - console.log(props) |
18 | | - |
| 19 | + this.state = { |
| 20 | + isDarkMode: this.props.theme.key === 'Dark Mode' ? true : false |
| 21 | + } |
19 | 22 | } |
20 | 23 |
|
21 | 24 | onLogOut() { |
22 | 25 | store.dispatch({ |
23 | 26 | type: loginTypes.LOGOUT |
24 | 27 | }); |
25 | 28 | } |
| 29 | + onThemeChange() { |
| 30 | + this.props.setTheme(this.state.isDarkMode ? 'Light Mode' : 'Dark Mode'); |
| 31 | + storageService.setThemeId(this.state.isDarkMode ? 'Light Mode' : 'Dark Mode'); |
| 32 | + this.setState((prev) => ({ isDarkMode: !prev.isDarkMode })) |
| 33 | + } |
26 | 34 | render() { |
27 | | - return ( |
28 | | - <Container> |
29 | | - <Header |
30 | | - barStyle="dark-content" |
31 | | - statusbarColor="white"> |
32 | | - <HeaderLeft /> |
33 | | - <HeaderBody> |
34 | | - <Text style={[GlobalStyle.headerTitle]}>Boilerplate</Text> |
35 | | - </HeaderBody> |
36 | | - <HeaderRight /> |
37 | | - </Header> |
38 | | - <Content> |
39 | | - </Content> |
40 | | - <Footer> |
41 | | - <Button |
42 | | - onClick={()=> this.onLogOut()} |
43 | | - style={{backgroundColor: 'red'}}> |
44 | | - <Text style={{color:'white'}}>Logout</Text> |
45 | | - </Button> |
46 | | - </Footer> |
47 | | - </Container> |
48 | | - ) |
| 35 | + const { isDarkMode } = this.state; |
| 36 | + const { theme } = this.props; |
| 37 | + return ( |
| 38 | + <Container> |
| 39 | + <Header |
| 40 | + barStyle="dark-content" |
| 41 | + statusbarColor="white"> |
| 42 | + <HeaderLeft /> |
| 43 | + <HeaderBody> |
| 44 | + <Text style={[GlobalStyle.headerTitle]}>Boilerplate</Text> |
| 45 | + </HeaderBody> |
| 46 | + <HeaderRight /> |
| 47 | + </Header> |
| 48 | + <Content style={{ |
| 49 | + backgroundColor: theme.backgroundColor |
| 50 | + }}> |
| 51 | + <Text style={{ |
| 52 | + marginBottom: 40, |
| 53 | + color: theme.color, |
| 54 | + fontWeight: 'bold' |
| 55 | + }}>Switch Theme</Text> |
| 56 | + <View style={styles.switchContainer}> |
| 57 | + <Text style={{ color: theme.color, |
| 58 | + fontSize: isDarkMode ? 14 : 16, |
| 59 | + fontWeight: isDarkMode ? '100' : 'bold' }}>{'Light Mode'}</Text> |
| 60 | + <Switch |
| 61 | + onValueChange={() => this.onThemeChange()} |
| 62 | + value={isDarkMode} /> |
| 63 | + <Text style={{ color: theme.color, |
| 64 | + fontSize: isDarkMode ? 16 : 14, |
| 65 | + fontWeight: isDarkMode ? 'bold' : '100' }}>{'Dark Mode'}</Text> |
| 66 | + </View> |
| 67 | + </Content> |
| 68 | + <Footer> |
| 69 | + <Button |
| 70 | + onClick={() => this.onLogOut()} |
| 71 | + style={{ backgroundColor: 'red' }}> |
| 72 | + <Text style={{ color: 'white' }}>Logout</Text> |
| 73 | + </Button> |
| 74 | + </Footer> |
| 75 | + </Container> |
| 76 | + ) |
49 | 77 | } |
50 | 78 | } |
51 | 79 |
|
| 80 | +export const SidemenuScreen = wrapTheme(Sidemenu); |
52 | 81 | const styles = StyleSheet.create({ |
53 | 82 | container: { |
54 | 83 | flex: 1, |
55 | 84 | }, |
| 85 | + switchContainer: { |
| 86 | + flexDirection: 'row', |
| 87 | + justifyContent: 'space-evenly', |
| 88 | + alignItems: 'center', |
| 89 | + } |
56 | 90 | }); |
0 commit comments