-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
36 lines (32 loc) · 900 Bytes
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react';
import {Theme} from './types';
import styled from 'styled-components/native';
import ThemeManager, {useTheme} from './contexts/ManageThemeContext';
import {Switch} from 'react-native';
const Home = () => {
// Helper function => useContext(ManageThemeContext)
const theme = useTheme();
return (
<Container>
<Switch
value={theme.mode === 'dark'}
onValueChange={value => theme.setMode(value ? 'dark' : 'light')}
/>
</Container>
);
};
// Get the background color from the theme object
const Container = styled.View<Theme>`
flex: 1;
justify-content: center;
align-items: center;
background: ${props => props.theme.background};
`;
// Wrap Home in the ThemeManager so it can access the current theme and
// the function to update it
const App = () => (
<ThemeManager>
<Home />
</ThemeManager>
);
export default App;