-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.tsx
89 lines (78 loc) · 1.79 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { useContext } from 'react';
import { observer } from 'mobx-react-lite';
import appContext from './src/models/RootStore';
import styled from 'styled-components/native';
const App: React.FC = () => {
const appCtx = useContext(appContext);
const [name, setName] = React.useState('');
const saveName = () => {
console.log('Save pressed.');
appCtx.github.setName(name);
};
if (appCtx.loading) {
return (
<Container>
<Loading>Loading</Loading>
<StatusBar style="auto" />
</Container>
);
}
return (
<Container>
<Detail>{`Your github username is ${
appCtx.github.name ? appCtx.github.name : 'not set.'
}`}</Detail>
<Header>Change Username</Header>
<UserName
placeholder="Desired Username"
defaultValue={name}
numberOfLines={1}
onChangeText={(text) => setName(text)}
/>
<SaveWrap onPress={saveName}>
<Save>Save</Save>
</SaveWrap>
<StatusBar style="auto" />
</Container>
);
};
const Loading = styled.Text`
font-size: 25px;
`;
const Container = styled.View`
flex: 1;
background: #fff;
align-items: center;
justify-content: center;
`;
const Detail = styled.Text`
font-size: 15px;
`;
const Header = styled.Text`
font-size: 20px;
font-weight: bold;
`;
const UserName = styled.TextInput`
border: 1px solid #666;
width: 200px;
height: 30px;
margin: 10px;
padding: 5px;
`;
const SaveWrap = styled.TouchableOpacity`
margin: 10px;
display: flex;
justify-content: center;
`;
const Save = styled.Text`
background: green;
font-weight: bold;
color: #fff;
width: 100px;
height: 30px;
padding: 5px;
text-align: center;
`;
export default observer(App);