Skip to content

Commit c48c0eb

Browse files
authored
Merge branch 'main' into Jacob_Mayhue-Themes
2 parents 6707a78 + 68169de commit c48c0eb

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

Navigation/RootStack.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
11
import { createNativeStackNavigator } from '@react-navigation/native-stack';
2-
import React, { useContext } from 'react';
2+
import React, { useContext, useEffect, useState } from 'react';
3+
import { Platform } from 'react-native';
4+
import NfcManager from 'react-native-nfc-manager';
35
import { AuthContext } from '../App';
46
import AuthenticationScreen from '../Auth/AuthenticationScreen';
7+
import NfcEnabledScreen from '../Nfc/NfcEnabledScreen';
58
import NavBar from './NavBar';
69

710
const Stack = createNativeStackNavigator();
11+
type NfcState = 'enabled' | 'disabled' | 'unsupported';
812

913
function RootStack() {
14+
const [nfcEnabled, setNfcEnabled] = useState<NfcState>('disabled');
15+
16+
useEffect(() => {
17+
const isEnabled = async () => {
18+
try {
19+
const isSupported = await NfcManager.isSupported();
20+
if (!isSupported) {
21+
setNfcEnabled('unsupported');
22+
return;
23+
}
24+
if (Platform.OS === 'android') {
25+
const enabled = await NfcManager.isEnabled();
26+
setNfcEnabled(enabled ? 'enabled' : 'disabled');
27+
} else if (Platform.OS === 'ios') {
28+
setNfcEnabled('enabled');
29+
} else {
30+
// Platform.OS === "windows" | "macos" | "web"
31+
console.log('Not a valid platform for NFC');
32+
}
33+
} catch (error) {
34+
console.error('Error fetching data:', error);
35+
}
36+
};
37+
isEnabled();
38+
}, []);
39+
1040
const auth = useContext(AuthContext);
1141
return (
1242
<Stack.Navigator
1343
screenOptions={{
1444
headerShown: false,
1545
}}
1646
>
17-
{auth?.authenticated ? (
47+
{nfcEnabled !== 'enabled' ? (
48+
<Stack.Screen name="NfcEnabledScreen">
49+
{() => <NfcEnabledScreen nfcEnabled={nfcEnabled} />}
50+
</Stack.Screen>
51+
) : auth?.authenticated ? (
1852
<Stack.Screen name="Main" component={NavBar} />
1953
) : (
2054
<Stack.Screen name="Authentication">{() => <AuthenticationScreen />}</Stack.Screen>

Nfc/NfcEnabledScreen.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import MaterialIcons from '@react-native-vector-icons/material-icons';
2+
import React, { useState } from 'react';
3+
import { Button, StyleSheet, Text, View } from 'react-native';
4+
import nfcManager from 'react-native-nfc-manager';
5+
6+
type NfcEnabledProps = {
7+
nfcEnabled: string;
8+
};
9+
10+
function NfcEnabledScreen({ nfcEnabled }: NfcEnabledProps) {
11+
const [restart, setRestart] = useState(false);
12+
13+
const enableNfc = async () => {
14+
await nfcManager.goToNfcSetting();
15+
setRestart(true);
16+
return;
17+
};
18+
19+
return (
20+
<>
21+
{nfcEnabled === 'unsupported' ? (
22+
<View style={styles.view}>
23+
<MaterialIcons
24+
name={'error-outline'}
25+
size={100}
26+
color="#b00020"
27+
style={styles.errorIcon}
28+
/>
29+
<Text style={styles.headerText}>NFC is unsupported</Text>
30+
<Text style={styles.bodyText}>NFC capability is unsupported on this device.</Text>
31+
</View>
32+
) : !restart ? (
33+
<View style={styles.view}>
34+
<MaterialIcons
35+
name={'error-outline'}
36+
size={100}
37+
color="#b00020"
38+
style={styles.errorIcon}
39+
/>
40+
<Text style={styles.headerText}>NFC is disabled</Text>
41+
<Text style={styles.bodyText}>Please enable NFC and restart the app to continue</Text>
42+
<Button onPress={enableNfc} color="#EEB211" title="Enable NFC" />
43+
</View>
44+
) : (
45+
<View style={styles.view}>
46+
<MaterialIcons
47+
name={'error-outline'}
48+
size={100}
49+
color="#B78300"
50+
style={styles.errorIcon}
51+
/>
52+
<Text style={styles.headerText}>Restart to continue</Text>
53+
<Text style={styles.bodyText}>
54+
{`If you've enabled NFC, just restart the app and you'll be on your way!`}
55+
</Text>
56+
</View>
57+
)}
58+
</>
59+
);
60+
}
61+
62+
const styles = StyleSheet.create({
63+
bodyText: {
64+
fontSize: 20,
65+
marginBottom: 20,
66+
textAlign: 'center',
67+
},
68+
errorIcon: {
69+
padding: 10,
70+
},
71+
headerText: {
72+
fontSize: 30,
73+
},
74+
view: {
75+
alignItems: 'center',
76+
flex: 1,
77+
justifyContent: 'center',
78+
margin: 10,
79+
},
80+
});
81+
82+
export default NfcEnabledScreen;

0 commit comments

Comments
 (0)