-
Notifications
You must be signed in to change notification settings - Fork 14
/
App.tsx
289 lines (267 loc) · 7.6 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import React, {useEffect, useState} from 'react';
import {
Image,
Modal,
NativeEventEmitter,
Pressable,
StyleSheet,
Text,
View,
NativeModules,
Platform,
} from 'react-native';
import {DefaultTheme, Provider as PaperProvider} from 'react-native-paper';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import Ionicons from 'react-native-vector-icons/Ionicons';
import NfcManager from 'react-native-nfc-manager';
import Toast from 'react-native-toast-message';
import CreateBoltcardScreen from './src/screens/CreateBoltcardScreen';
import ProgramBoltcardScreen from './src/screens/ProgramBoltcardScreen';
import HelpScreen from './src/screens/HelpScreen';
import ReadNFCScreen from './src/screens/ReadNFCScreen';
import ResetKeysScreen from './src/screens/ResetKeysScreen';
import ScanScreen from './src/screens/ScanScreen';
import ResetBoltcardScreen from './src/screens/ResetBoltcardScreen';
import {LogBox} from 'react-native';
LogBox.ignoreLogs(['Warning: ...']); // Ignore log notification by message
LogBox.ignoreAllLogs();
const theme = {
...DefaultTheme,
dark: false,
roundness: 2,
colors: {
...DefaultTheme.colors,
primary: 'tomato',
accent: '#f1c40f',
},
};
const Tab = createBottomTabNavigator();
const CreateBoltcardStack = createNativeStackNavigator();
const Stack = createNativeStackNavigator();
const AdvancedStack = createNativeStackNavigator();
function CreateBoltcardStackScreen() {
return (
<CreateBoltcardStack.Navigator
screenOptions={{
headerShown: false,
}}>
<CreateBoltcardStack.Screen
name="CreateBoltcardScreen"
component={CreateBoltcardScreen}
initialParams={{data: null}}
/>
<CreateBoltcardStack.Screen name="ScanScreen" component={ScanScreen} />
</CreateBoltcardStack.Navigator>
);
}
function LogoTitle(props) {
return (
<View style={{flexDirection: 'row'}}>
<Image
style={{width: 50, height: 50, marginRight: 10, marginTop: 0}}
source={{
uri: 'https://avatars.githubusercontent.com/u/109875636?s=200&v=4',
}}
/>
<Text style={{lineHeight: 50, fontSize: 20}}>{props.title}</Text>
</View>
);
}
const ErrorModal = props => {
const {modalVisible, setModalVisible, modalText} = props;
return (
<View style={styles.centeredView}>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
setModalVisible(!modalVisible);
}}>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Ionicons name="warning" size={30} color="red" />
<Text style={styles.modalText}>{modalText}</Text>
<Pressable
style={[styles.button, styles.buttonClose]}
onPress={() => setModalVisible(!modalVisible)}>
<Text style={styles.textStyle}>Close</Text>
</Pressable>
</View>
</View>
</Modal>
</View>
);
};
NfcManager.start();
function HomeTabs() {
return (
<Tab.Navigator
screenOptions={({route}) => ({
tabBarIcon: ({focused, color, size}) => {
let iconName;
if (route.name === 'Create Bolt Card') {
iconName = focused ? 'card' : 'card-outline';
} else if (route.name === 'Help') {
iconName = focused ? 'information' : 'information-outline';
} else if (route.name === 'Advanced') {
iconName = focused ? 'settings' : 'settings-outline';
} else if (route.name === 'Read NFC') {
iconName = focused ? 'book' : 'book-outline';
} else if (route.name === 'Reset Keys') {
iconName = focused ? 'key' : 'key-outline';
}
// You can return any component that you like here!
return <Ionicons name={iconName} size={size} color={color} />;
},
tabBarActiveTintColor: '#f58340',
tabBarInactiveTintColor: 'gray',
})}>
<Tab.Screen
name="Create Bolt Card"
children={() => <CreateBoltcardStackScreen />}
options={{
headerTitle: props => (
<LogoTitle title="Create Bolt Card" {...props} />
),
}}
/>
<Tab.Screen
name="Reset Keys"
children={() => (
<CreateBoltcardStack.Navigator
screenOptions={{
headerShown: false,
}}>
<CreateBoltcardStack.Screen
name="ResetKeysScreen"
component={ResetKeysScreen}
initialParams={{data: null}}
/>
<CreateBoltcardStack.Screen
name="ScanScreen"
component={ScanScreen}
/>
</CreateBoltcardStack.Navigator>
)}
/>
<Tab.Screen name="Read NFC" component={ReadNFCScreen} />
<Tab.Screen
name="Help"
component={HelpScreen}
options={{headerTitle: props => <LogoTitle title="Help" {...props} />}}
/>
{/* <Tab.Screen
name="Test"
component={TestScreen}
/> */}
</Tab.Navigator>
);
}
export default function App(props) {
const [modalVisible, setModalVisible] = useState(false);
const [modalText, setModalText] = useState();
const showModalError = errorText => {
setModalText(errorText);
setModalVisible(true);
};
const linking = {
prefixes: ['boltcard://'],
config: {
screens: {
Program: 'program',
Reset: 'reset',
},
},
};
useEffect(() => {
if (Platform.OS == 'android') {
const eventEmitter = new NativeEventEmitter();
const eventListener = eventEmitter.addListener('NFCError', event => {
setModalText(event.message);
setModalVisible(true);
});
return () => {
eventListener.remove();
};
}
}, []);
return (
<PaperProvider theme={theme}>
<NavigationContainer linking={linking} fallback={<Text>Loading...</Text>}>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeTabs}
options={{
headerShown: false,
}}
/>
<Stack.Screen name="Program" component={ProgramBoltcardScreen} />
<Stack.Screen name="Reset" component={ResetBoltcardScreen} />
</Stack.Navigator>
</NavigationContainer>
<ErrorModal
modalText={modalText}
modalVisible={modalVisible}
setModalVisible={setModalVisible}
/>
<Toast />
</PaperProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
button: {
alignItems: 'center',
backgroundColor: '#DDDDDD',
padding: 10,
},
centeredView: {
justifyContent: 'center',
alignItems: 'center',
},
modalView: {
margin: 20,
backgroundColor: 'white',
borderRadius: 20,
padding: 35,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
button: {
borderRadius: 20,
padding: 10,
elevation: 2,
},
buttonOpen: {
backgroundColor: '#F194FF',
},
buttonClose: {
backgroundColor: '#2196F3',
},
textStyle: {
color: 'white',
fontWeight: 'bold',
textAlign: 'center',
},
modalText: {
marginBottom: 15,
textAlign: 'center',
},
});