/
App.tsx
162 lines (147 loc) · 4.85 KB
/
App.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import React, {useLayoutEffect, useRef} from 'react';
import {StatusBar, Linking} from 'react-native';
import analytics from '@react-native-firebase/analytics';
import {NavigationContainer} from '@react-navigation/native';
import {AppProvider} from './src/context/appContext';
import {AuthProvider} from './src/context/authContext';
import {RequestProvider} from './src/context/requestContext';
import {LeagueProvider} from './src/context/leagueContext';
import AppIndex from './src/screens';
import {APP_COLORS, NavTheme} from './src/utils/designSystem';
import {I18nProvider} from '@lingui/react';
import i18n from './src/utils/i18n';
import {ActionSheetProvider} from '@expo/react-native-action-sheet';
import RNBootSplash from 'react-native-bootsplash';
import dynamicLinks from '@react-native-firebase/dynamic-links';
import {MatchProvider} from './src/context/matchContext';
import {ArticlesProvider} from './src/context/articlesContext';
import AsyncStorage from '@react-native-async-storage/async-storage';
const App = () => {
const routeNameRef = useRef();
const navigationRef = useRef();
const getFirUrl = async () => {
const firUrl = await dynamicLinks()
.getInitialLink()
.then((link) => link);
return firUrl;
};
const linking = {
prefixes: ['https://l.proclubs.zone', 'proclubs://'],
async getInitialURL() {
const firUrl = await getFirUrl();
const getLink = await Linking.getInitialURL();
if (firUrl) {
console.log('firUrl', firUrl);
if (firUrl.url.length > 34) {
return firUrl.url;
}
}
if (getLink) {
console.log('getLink', getLink);
// if (getLink.includes('firebaseapp')) {
// // await AsyncStorage.setItem('@storage_Url', getLink);
// }
if (getLink.length > 34) {
return getLink;
}
}
},
subscribe(listener) {
const onReceiveURL = async ({url}: {url: string}) => {
console.log('receive url', url);
// listener(url);
if (url.length > 34) {
listener(url);
}
// if (url.includes('firebaseapp')) {
// // await AsyncStorage.setItem('@storage_Url', url);
// }
};
Linking.addEventListener('url', onReceiveURL);
const unsubscribe = dynamicLinks().onLink(onReceiveURL);
return () => {
unsubscribe();
Linking.removeEventListener('url', onReceiveURL);
};
},
config: {
initialRouteName: 'Home',
screens: {
League: 'lgu/:leagueId',
'Reset Password': 'eml/',
},
},
};
useLayoutEffect(() => {
RNBootSplash.hide({fade: true});
const getLanguage = async () => {
try {
const value = await AsyncStorage.getItem('@language');
console.log('langvalue', value);
if (value !== null && value !== i18n.locale) {
console.log('langvalupdate,', value);
return i18n.activate(value);
}
i18n.activate('en');
} catch (e) {
throw new Error(e);
}
};
getLanguage();
}, []);
return (
<>
<StatusBar
barStyle="dark-content"
translucent={true}
backgroundColor={APP_COLORS.Accent}
/>
<I18nProvider i18n={i18n}>
<AuthProvider>
<AppProvider>
<RequestProvider>
<LeagueProvider>
<MatchProvider>
<NavigationContainer
theme={NavTheme}
linking={linking}
ref={navigationRef}
onReady={() =>
(routeNameRef.current = navigationRef.current.getCurrentRoute().name)
}
onStateChange={async () => {
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef.current.getCurrentRoute()
.name;
if (previousRouteName !== currentRouteName) {
await analytics().logScreenView({
screen_name: currentRouteName,
screen_class: currentRouteName,
});
}
}}>
<ArticlesProvider>
<ActionSheetProvider>
<AppIndex />
</ActionSheetProvider>
</ArticlesProvider>
</NavigationContainer>
</MatchProvider>
</LeagueProvider>
</RequestProvider>
</AppProvider>
</AuthProvider>
</I18nProvider>
</>
);
};
export default App;