-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
88 lines (80 loc) · 2.57 KB
/
App.js
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
import React, { useEffect, useState } from 'react';
import { Linking } from 'react-native';
import * as Appcues from '@appcues/react-native';
import { DefaultTheme, NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import UserContext from './contexts/UserContext';
import SignInScreen from './screens/signin/SignInScreen';
import MainScreen from './screens/main/MainScreen';
import { PlainButton } from './components/Button';
const RootStack = createNativeStackNavigator();
export default function App() {
// App state for current user ID, which is used in the
// UserContext.Provider below to make accessible to other elements
// in the view hierarchy (sign in screen, profile screen)
const [userID, setUserID] = useState('default-00000');
// Ensures that first _real_ render of the app doesn't occur until
// SDK init complete - to avoid screen view analytics before SDK is ready
const [initComplete, setInitComplete] = useState(false);
useEffect(() => {
const initializeSdk = async () => {
await Appcues.setup('APPCUES_ACCOUNT_ID', 'APPCUES_APPLICATION_ID');
setInitComplete(true);
};
initializeSdk();
}, []);
return (
<UserContext.Provider value={{ userID, setUserID }}>
{initComplete && <RootView />}
</UserContext.Provider>
);
}
function RootView() {
return (
<NavigationContainer
theme={{
...DefaultTheme,
colors: {
...DefaultTheme.colors,
primary: '#1EB5C4',
background: `#FFFFFF`,
border: `#FFFFFF`,
},
}}
>
<RootStack.Navigator>
<RootStack.Screen
name="Sign In"
component={SignInScreen}
options={({ navigation }) => ({
headerShadowVisible: false,
headerTitleStyle: { fontWeight: '600' },
headerRight: () => (
<PlainButton
title="Skip"
onPress={() => {
navigation.navigate('Main');
}}
/>
),
})}
/>
<RootStack.Screen
name="Main"
component={MainScreen}
options={{
presentation: 'fullScreenModal',
animation: 'fade',
headerShown: false,
}}
/>
</RootStack.Navigator>
</NavigationContainer>
);
}
Linking.addEventListener('url', async ({ url }) => {
const appcuesDidHandleURL = await Appcues.didHandleURL(url);
if (!appcuesDidHandleURL) {
// Handle a non-Appcues URL
}
});