-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
90 lines (77 loc) · 2.58 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
89
90
import React from 'react';
import * as SplashScreen from 'expo-splash-screen';
import * as Font from 'expo-font';
import { Block, GalioProvider } from 'galio-framework';
import { NavigationContainer } from '@react-navigation/native';
import 'react-native-get-random-values';
import Screens from './navigation/Screens';
import { nowTheme } from './constants';
import { ApolloClient, ApolloProvider, createHttpLink, InMemoryCache } from '@apollo/client';
import { Auth0Provider } from 'react-native-auth0';
import { setContext } from '@apollo/client/link/context';
import * as SecureStore from 'expo-secure-store';
import { GlobalProvider } from './GlobalContext';
const httpLink = createHttpLink({
uri: 'https://carbonara-core-mkvkriomda-ew.a.run.app/graphql',
});
const authLink = setContext(async (_, { headers }) => {
const token = await SecureStore.getItemAsync('jwt_token');
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : "",
}
}
});
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
});
export default class App extends React.Component {
state = {
isLoadingComplete: false,
fontLoaded: false
};
componentDidMount() {
SplashScreen.preventAutoHideAsync();
this._loadResourcesAsync();
}
render() {
if (!this.state.isLoadingComplete) {
return null; // Keep the splash screen visible while resources are loading
}
return (
<Auth0Provider domain={"dev-yntwqm72gdl58ssy.us.auth0.com"} clientId={"df43s61p15MI3pp7UoBPV0tEQ0DA6dIc"}>
<ApolloProvider client={client}>
<GlobalProvider>
<NavigationContainer>
<GalioProvider theme={nowTheme}>
<Block flex>
<Screens />
</Block>
</GalioProvider>
</NavigationContainer>
</GlobalProvider>
</ApolloProvider>
</Auth0Provider>
);
}
_loadResourcesAsync = async () => {
try {
await Font.loadAsync({
'montserrat-regular': require('./assets/font/Montserrat-Regular.ttf'),
'montserrat-bold': require('./assets/font/Montserrat-Bold.ttf'),
'next-sphere-black': require('./assets/font/Next-Sphere-Black.ttf'),
'next-sphere-thin': require('./assets/font/Next-Sphere-Thin.ttf'),
});
this.setState({ isLoadingComplete: true }, async () => {
await SplashScreen.hideAsync();
});
} catch (error) {
this._handleLoadingError(error);
}
};
_handleLoadingError = error => {
console.warn("Loading error: ", error);
};
}