-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
177 lines (162 loc) · 6.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*
*/
import 'react-native-gesture-handler';
import React, {useEffect, useState} from 'react';
import type {Node} from 'react';
import firestore from '@react-native-firebase/firestore';
import {ScrollView, StatusBar, StyleSheet, Text, TouchableOpacity, useColorScheme, View} from 'react-native';
import {
Colors,
DebugInstructions,
Header,
LearnMoreLinks,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import LoginPage from '@pages/LoginPage';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {SafeAreaView} from 'react-native-safe-area-context';
import SplashPage from '@pages/SplashPage';
import {DefaultTheme, Portal, Provider as PaperProvider} from 'react-native-paper';
import {CustomColors, CustomTypography} from '@styles';
import Icon from 'react-native-vector-icons/MaterialIcons';
import RegisterPage from '@pages/RegisterPage';
import {GoogleSignin} from 'react-native-google-signin';
import {useSelector, useDispatch} from 'react-redux';
import auth from '@react-native-firebase/auth';
import RootStack from '@navigations/RootStack';
import {setLoginBlock} from '@slices/appSlice';
import UserService from '@services/UserService';
import FlashMessage from 'react-native-flash-message';
import {PortalProvider} from '@gorhom/portal';
import BottomSheet from 'react-native-bottomsheet-reanimated';
import ImageCropPicker from 'react-native-image-crop-picker';
import FontAwesome from 'react-native-vector-icons/FontAwesome';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {LocalNotification} from '~firebaseCloudMessaging/LocalPushController';
import RemotePushController from '~firebaseCloudMessaging/RemotePushController';
import {StripeProvider} from '@stripe/stripe-react-native';
import PaymentService from '@services/PaymentService';
import {PUBLISHABLE_KEY} from '@env';
const Stack = createStackNavigator();
const theme = {
...DefaultTheme,
roundness: 2,
colors: {
...DefaultTheme.colors,
primary: '#3498db',
accent: '#f1c40f',
background: CustomColors.WHITE,
surface: CustomColors.WHITE,
backdrop: 'rgba(0,0,0,0.5)',
error: 'red',
},
};
const App: () => Node = () => {
const isDarkMode = useColorScheme() === 'dark';
const isLoading = useSelector(state => state.appState.isLoading);
const loggedInAcctype = useSelector(state => state.loginState.userInfo?.accType);
const [isAuth, setIsAuth] = useState(false);
const dispatch = useDispatch();
const loginBlock = useSelector(state => state.appState.loginBlock);
const userInfo = useSelector(state => state.loginState.userInfo);
const [publishableKey, setPublishableKey] = useState(PUBLISHABLE_KEY);
const backgroundStyle = {
backgroundColor: 'blue',
};
var autoFetchLocked = false;
useEffect(() => {
GoogleSignin.configure({
scopes: ['email'], // what API you want to access on behalf of the user, default is email and profile
webClientId: '105438375417-c1h6v0v6a19l8od4mb1ellpfs0i35j91.apps.googleusercontent.com', // client ID of type WEB for your server (needed to verify user ID and offline access)
offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVER
});
const authenticationListener = auth().onAuthStateChanged(user => {
// LocalNotification()
console.log('User is authenticated');
if (!user) {
autoFetchLocked = true;
}
if (!!auth().currentUser) {
if (!autoFetchLocked) {
UserService.fetchLoggedInUserDataToRedux()
.then(() => {
//LoggedIn'
})
.catch(err => {});
} else {
autoFetchLocked = false;
}
} else {
setIsAuth(false);
dispatch(setLoginBlock(false));
}
});
return authenticationListener;
}, []);
useEffect(() => {
if (!!userInfo) {
setIsAuth(true);
}
}, [userInfo]);
return (
<PaperProvider
settings={{
icon: props => <Icon {...props} />,
}}
theme={theme}>
<StripeProvider publishableKey={publishableKey}>
<SafeAreaProvider>
<GestureHandlerRootView style={{width: '100%', height: '100%', flex: 1}}>
<PortalProvider>
<NavigationContainer>
<RootStack
isAuth={isAuth}
isLoading={isLoading}
loginBlock={loginBlock}
loggedInAcctype={loggedInAcctype}></RootStack>
{/* <Stack.Navigator screenOptions={{unmountInactiveRoutes: true, unmountOnBlur: true}}>
<Stack.Screen name="SplashPage" component={SplashPage} options={{headerShown: false}} />
<Stack.Screen name="LoginPage" component={LoginPage} options={{headerShown: false}} />
<Stack.Screen name="RegisterPage" component={RegisterPage} options={{headerShown: false}} />
</Stack.Navigator> */}
</NavigationContainer>
<FlashMessage
textStyle={{
fontFamily: CustomTypography.FONT_FAMILY_REGULAR,
fontSize: CustomTypography.FONT_SIZE_14,
}}
/>
<RemotePushController />
</PortalProvider>
</GestureHandlerRootView>
</SafeAreaProvider>
</StripeProvider>
</PaperProvider>
);
};
const styles = StyleSheet.create({
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
},
highlight: {
fontWeight: '700',
},
});
export default App;