-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from sarthakpranesh/develop
Release v3.0.0
- Loading branch information
Showing
90 changed files
with
8,702 additions
and
3,181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/web-build | ||
.expo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,9 @@ buck-out/ | |
/ios/Pods/ | ||
|
||
.env | ||
|
||
# Expo used for web and web builds | ||
/.expo | ||
/web-build | ||
|
||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,156 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import React, { useEffect } from 'react' | ||
import { bindActionCreators } from 'redux' | ||
import { Provider as ReduxProvider, connect } from 'react-redux' | ||
import { PersistGate } from 'redux-persist/integration/react' | ||
import { PermissionsAndroid, Platform } from 'react-native' | ||
import Geolocation from 'react-native-geolocation-service' | ||
import LinearGradient from 'react-native-linear-gradient' | ||
import { NavigationContainer } from '@react-navigation/native' | ||
import { createAppContainer, createSwitchNavigator } from 'react-navigation' | ||
import { createDrawerNavigator } from '@react-navigation/drawer' | ||
import { SafeAreaProvider } from 'react-native-safe-area-context' | ||
import { preventAutoHideAsync, hideAsync } from 'expo-splash-screen' | ||
|
||
import Animated from 'react-native-reanimated' | ||
// importing redux persist stores | ||
import { store, persister } from './src/stores/stores' | ||
|
||
import { DrawerContent, Screens } from './src/components/navigation/Drawer' | ||
// Importing reducer functions | ||
import { setCountry, updateData } from './src/reducers/DataReducer' | ||
|
||
import getLocationHook from './src/hooks/getLocationHook' | ||
// Importing API functions | ||
import getCountry from './src/API/functions/getCountry' | ||
import getCovidData from './src/API/functions/getCovidData' | ||
|
||
const Drawer = createDrawerNavigator() | ||
// Importing splash screen | ||
import WebSplashScreen from './src/screens/SplashScreen' | ||
import HomeScreen from './src/screens/HomeScreen' | ||
|
||
const MainApp = () => { | ||
const [getLocation, country] = getLocationHook() | ||
const [progress, setProgress] = useState<Animated.Node<number>>( | ||
new Animated.Value(0) | ||
const mapStateToProps = (state: any) => { | ||
const data = state.dataReducer.data | ||
return data | ||
} | ||
|
||
const mapDispatchToProps = (dispatch: any) => | ||
bindActionCreators( | ||
{ | ||
setCountry, | ||
updateData | ||
}, | ||
dispatch | ||
) | ||
const scale = Animated.interpolate(progress, { | ||
inputRange: [0, 1], | ||
outputRange: [1, 0.8] | ||
}) | ||
const borderRadius = Animated.interpolate(progress, { | ||
inputRange: [0, 1], | ||
outputRange: [0, 16] | ||
}) | ||
|
||
const animatedStyle = { borderRadius, transform: [{ scale }] } | ||
const MainApp = connect(mapStateToProps, mapDispatchToProps)((props: any) => { | ||
const fetchAndSetCountry = async (coords: any) => { | ||
const country = await getCountry({ | ||
long: coords.longitude, | ||
lat: coords.latitude | ||
}) | ||
props.setCountry(country) | ||
} | ||
|
||
useEffect(() => { | ||
// some bug in react native | ||
setTimeout(() => { | ||
if (Platform.OS === 'ios') { | ||
Geolocation.requestAuthorization('whenInUse') | ||
.then((result) => { | ||
console.log('IOS permission:', result) | ||
Geolocation.getCurrentPosition( | ||
async (pos) => { | ||
await getLocation({ | ||
long: pos.coords.longitude, | ||
lat: pos.coords.latitude | ||
}) | ||
}, | ||
(err) => { | ||
console.log(err.message) | ||
getLocation({ lat: '28.644800', long: '77.216721' }) | ||
}, | ||
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } | ||
) | ||
}) | ||
.catch((err) => console.log(err.message)) | ||
} else { | ||
PermissionsAndroid.request( | ||
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, | ||
{ | ||
title: 'Covid-19 App', | ||
message: | ||
"App needs to access your phone's location to work correctly. " + | ||
'You can cancel this step but then app will default to Indian Stats', | ||
buttonNeutral: 'Ask Me Later', | ||
buttonNegative: 'Cancel', | ||
buttonPositive: 'OK' | ||
} | ||
) | ||
.then(() => { | ||
Geolocation.getCurrentPosition( | ||
async (pos) => { | ||
await getLocation({ | ||
long: pos.coords.longitude, | ||
lat: pos.coords.latitude | ||
}) | ||
}, | ||
(err) => { | ||
console.log(err.message) | ||
getLocation({ lat: '28.644800', long: '77.216721' }) | ||
}, | ||
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } | ||
) | ||
}) | ||
.catch((err) => console.log(err.message)) | ||
switch (Platform.OS) { | ||
case 'web': | ||
Geolocation.getCurrentPosition( | ||
(pos) => fetchAndSetCountry(pos.coords), | ||
(err) => { | ||
console.log(err.message) | ||
fetchAndSetCountry({ latitude: '28.644800', longitude: '77.216721' }) | ||
}, | ||
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } | ||
) | ||
return | ||
case 'ios': | ||
Geolocation.requestAuthorization('whenInUse') | ||
.then((result) => { | ||
console.log('IOS permission:', result) | ||
Geolocation.getCurrentPosition( | ||
(pos) => fetchAndSetCountry(pos.coords), | ||
(err) => { | ||
console.log(err.message) | ||
fetchAndSetCountry({ latitude: '28.644800', longitude: '77.216721' }) | ||
}, | ||
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } | ||
) | ||
}) | ||
.catch((err) => console.log(err.message)) | ||
return | ||
case 'android': | ||
PermissionsAndroid.request( | ||
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, | ||
{ | ||
title: 'Covid-19 App', | ||
message: | ||
"App needs to access your phone's location to work correctly. " + | ||
'You can cancel this step but then app will default to Indian Stats', | ||
buttonNeutral: 'Ask Me Later', | ||
buttonNegative: 'Cancel', | ||
buttonPositive: 'OK' | ||
} | ||
) | ||
.then(() => { | ||
Geolocation.getCurrentPosition( | ||
(pos) => fetchAndSetCountry(pos.coords), | ||
(err) => { | ||
console.log('Geolocation Error:', err.message) | ||
fetchAndSetCountry({ latitude: '28.644800', longitude: '77.216721' }) | ||
}, | ||
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 } | ||
) | ||
}) | ||
.catch((err) => console.log(err.message)) | ||
return | ||
default: | ||
console.log('No platform matched') | ||
} | ||
}, 100) | ||
}, []) | ||
|
||
return country !== '' ? ( | ||
<NavigationContainer> | ||
<LinearGradient | ||
colors={['#DEF7FF', '#B1ECFF']} | ||
style={{ flex: 1, backgroundColor: 'white' }}> | ||
<Drawer.Navigator | ||
edgeWidth={100} | ||
initialRouteName="Screens" | ||
drawerType="slide" | ||
overlayColor="transparent" | ||
drawerStyle={{ flex: 1, width: '50%', backgroundColor: 'transparent' }} | ||
drawerContentOptions={{ | ||
activeBackgroundColor: 'transparent', | ||
activeTintColor: 'black', | ||
inactiveTintColor: 'black' | ||
}} | ||
sceneContainerStyle={{ backgroundColor: 'transparent' }} | ||
drawerContent={(p) => { | ||
setProgress(p.progress) | ||
return <DrawerContent {...p} country={country} /> | ||
}}> | ||
<Drawer.Screen name="Screens"> | ||
{(p) => <Screens {...p} style={animatedStyle} country={country} />} | ||
</Drawer.Screen> | ||
</Drawer.Navigator> | ||
</LinearGradient> | ||
</NavigationContainer> | ||
) : null | ||
} | ||
useEffect(() => { | ||
if (props.country !== null) { | ||
getCovidData(props.country) | ||
.then((data) => { | ||
props.updateData(data) | ||
}) | ||
.catch((err) => { | ||
console.log(err) | ||
}) | ||
} | ||
}, [props.country]) | ||
|
||
// this useEffect should hide all implementation of splash screen from native and web | ||
useEffect(() => { | ||
if (props.data?.global !== undefined) { | ||
hideAsync() | ||
} | ||
}, [props.data?.global]) | ||
|
||
const UserStartingSwitch = createSwitchNavigator( | ||
{ | ||
MainApp | ||
}, | ||
{ | ||
initialRouteName: 'MainApp' | ||
// expo-splash-screen not supported on web | ||
// therefore using a extra stack with react native component for splash on web | ||
if (Platform.OS === 'web') { | ||
if (props.data?.global === undefined) { | ||
return <WebSplashScreen /> | ||
} | ||
} | ||
) | ||
|
||
export default createAppContainer(UserStartingSwitch) | ||
if (props.country === null || props.data?.global === undefined) { | ||
return null | ||
} | ||
|
||
return <HomeScreen /> | ||
}) | ||
|
||
const App = () => { | ||
useEffect(() => { | ||
preventAutoHideAsync() | ||
}, []) | ||
return ( | ||
<ReduxProvider store={store}> | ||
<PersistGate loading={false} persistor={persister}> | ||
<SafeAreaProvider> | ||
<MainApp /> | ||
</SafeAreaProvider> | ||
</PersistGate> | ||
</ReduxProvider> | ||
) | ||
} | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.