Skip to content

Commit 559cf43

Browse files
committed
Linter Fixes
1 parent 706524e commit 559cf43

File tree

2 files changed

+114
-88
lines changed

2 files changed

+114
-88
lines changed

Navigation/RootStack.tsx

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,53 @@ import NfcEnabledScreen from '../Nfc/NfcEnabledScreen';
88
import NavBar from './NavBar';
99

1010
const Stack = createNativeStackNavigator();
11-
type NfcState = "enabled" | "disabled" | "unsupported";
11+
type NfcState = 'enabled' | 'disabled' | 'unsupported';
1212

1313
function RootStack() {
14-
const [nfcEnabled, setNfcEnabled] = useState<NfcState>("disabled");
14+
const [nfcEnabled, setNfcEnabled] = useState<NfcState>('disabled');
1515

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 { // Platform.OS === "windows" | "macos" | "web"
30-
console.log("Not a valid platform for NFC");
31-
}
32-
33-
} catch (error) {
34-
console.error('Error fetching data:', error);
35-
}
16+
useEffect(() => {
17+
const isEnabled = async () => {
18+
try {
19+
const isSupported = await NfcManager.isSupported();
20+
if (!isSupported) {
21+
setNfcEnabled('unsupported');
22+
return;
3623
}
37-
isEnabled();
38-
}, []);
39-
40-
const auth = useContext(AuthContext)
41-
return (
42-
<Stack.Navigator
43-
screenOptions={{
44-
headerShown: false,
45-
}}
46-
>
47-
{ nfcEnabled !== "enabled"?
48-
<Stack.Screen name="NfcEnabledScreen">
49-
{() => <NfcEnabledScreen nfcEnabled={nfcEnabled} />}
50-
</Stack.Screen>
51-
:
52-
auth?.authenticated?
53-
<Stack.Screen name="Main" component={NavBar} />
54-
:
55-
<Stack.Screen name="Authentication">
56-
{() => <AuthenticationScreen />}
57-
</Stack.Screen>
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');
5832
}
59-
</Stack.Navigator>
60-
)
33+
} catch (error) {
34+
console.error('Error fetching data:', error);
35+
}
36+
};
37+
isEnabled();
38+
}, []);
39+
40+
const auth = useContext(AuthContext);
41+
return (
42+
<Stack.Navigator
43+
screenOptions={{
44+
headerShown: false,
45+
}}
46+
>
47+
{nfcEnabled !== 'enabled' ? (
48+
<Stack.Screen name="NfcEnabledScreen">
49+
{() => <NfcEnabledScreen nfcEnabled={nfcEnabled} />}
50+
</Stack.Screen>
51+
) : auth?.authenticated ? (
52+
<Stack.Screen name="Main" component={NavBar} />
53+
) : (
54+
<Stack.Screen name="Authentication">{() => <AuthenticationScreen />}</Stack.Screen>
55+
)}
56+
</Stack.Navigator>
57+
);
6158
}
6259

6360
export default RootStack;

Nfc/NfcEnabledScreen.tsx

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,82 @@
11
import MaterialIcons from '@react-native-vector-icons/material-icons';
22
import React, { useState } from 'react';
3-
import { Button, Text, View } from 'react-native';
3+
import { Button, StyleSheet, Text, View } from 'react-native';
44
import nfcManager from 'react-native-nfc-manager';
55

6-
type NfcEnabledProps = {
7-
nfcEnabled: string,
6+
type NfcEnabledProps = {
7+
nfcEnabled: string;
88
};
99

10-
function NfcEnabledScreen({nfcEnabled} : NfcEnabledProps) {
11-
const [restart, setRestart] = useState(false);
10+
function NfcEnabledScreen({ nfcEnabled }: NfcEnabledProps) {
11+
const [restart, setRestart] = useState(false);
1212

13-
const enableNfc = async () => {
14-
await nfcManager.goToNfcSetting();
15-
setRestart(true);
16-
return;
17-
}
13+
const enableNfc = async () => {
14+
await nfcManager.goToNfcSetting();
15+
setRestart(true);
16+
return;
17+
};
1818

19-
return (
20-
<>
21-
{
22-
nfcEnabled === "unsupported" ?
23-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', margin: 10 }}>
24-
<MaterialIcons name={"error-outline"} size={100} color="#b00020" style={{ padding: 10 }} />
25-
<Text style={{ fontSize: 30 }}>NFC is unsupported</Text>
26-
<Text style={{ fontSize: 20, textAlign: "center", marginBottom: 20 }}>
27-
NFC capability is unsupported on this device.
28-
</Text>
29-
</View>
30-
:
31-
!restart ?
32-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', margin: 10 }}>
33-
<MaterialIcons name={"error-outline"} size={100} color="#b00020" style={{ padding: 10 }} />
34-
<Text style={{ fontSize: 30 }}>NFC is disabled</Text>
35-
<Text style={{ fontSize: 20, textAlign: "center", marginBottom: 20 }}>
36-
Please enable NFC and restart the app to continue
37-
</Text>
38-
<Button onPress={enableNfc} color="#EEB211" title="Enable NFC" />
39-
</View>
40-
:
41-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', margin: 10 }}>
42-
<MaterialIcons name={"error-outline"} size={100} color="#B78300" style={{ padding: 10 }} />
43-
<Text style={{ fontSize: 30 }}>Restart to continue</Text>
44-
<Text style={{ fontSize: 20, textAlign: "center", marginBottom: 20 }}>
45-
If you've enabled NFC, just restart the app and you'll be on your way!
46-
</Text>
47-
</View>
48-
}
49-
</>
50-
);
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+
);
5160
}
5261

53-
export default NfcEnabledScreen;
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)