-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
onboarding.tsx
49 lines (42 loc) · 1.48 KB
/
onboarding.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
import { StackScreenProps } from '@react-navigation/stack';
import { useForegroundPermissions } from 'expo-location';
import { useCallback, useEffect } from 'react';
import { StackParamList } from '../providers/navigation';
import { Box, Button, Spinner, Title, Paragraph } from '../providers/theme';
type OnboardingScreenProps = StackScreenProps<StackParamList, 'Onboarding'>;
export function OnboardingScreen({ navigation }: OnboardingScreenProps) {
const [permission, askPermission] = useForegroundPermissions();
const onContinue = useCallback(() => {
navigation.navigate('Distance');
}, [navigation]);
useEffect(() => {
// Only redirect on first render or permission change,
// not when users go back to this screen.
if (permission?.granted) {
onContinue();
}
}, [onContinue, permission?.granted]);
if (permission?.granted) {
return (
<Box variant='page'>
<Box>
<Title>Permissions granted</Title>
<Paragraph>To monitor your office marathon, we need access to your location.</Paragraph>
</Box>
<Button onPress={onContinue}>Let's start!</Button>
</Box>
);
}
return (
<Box variant='page'>
<Box>
<Title>We need your permission</Title>
<Paragraph>To monitor your office marathon, we need access to your location.</Paragraph>
</Box>
{!permission
? <Spinner />
: <Button onPress={askPermission}>Grant permission</Button>
}
</Box>
);
};