Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthakpranesh committed Apr 13, 2021
2 parents 166f9df + 1d230e9 commit 146afa5
Show file tree
Hide file tree
Showing 18 changed files with 3,133 additions and 4,218 deletions.
73 changes: 0 additions & 73 deletions .flowconfig

This file was deleted.

94 changes: 33 additions & 61 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 { Platform } from 'react-native'
import Geolocation from 'react-native-geolocation-service'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { preventAutoHideAsync, hideAsync } from 'expo-splash-screen'
Expand All @@ -21,6 +21,20 @@ import getCovidData from './src/API/functions/getCovidData'
import WebSplashScreen from './src/screens/SplashScreen'
import HomeScreen from './src/screens/HomeScreen'

// Importing components
import GeolocationPermissions from './src/components/GeolocationPermissions/GeolocationPermissions'

// default location, if permission for location not provided
const INDIA: DefaultGeolocation.GeoCoordinates = {
latitude: 28.644800,
longitude: 77.216721,
accuracy: 0,
altitude: 0,
altitudeAccuracy: 0,
heading: 0,
speed: 0
}

const mapStateToProps = (state: any) => {
const data = state.dataReducer.data
return data
Expand All @@ -36,74 +50,32 @@ const mapDispatchToProps = (dispatch: any) =>
)

const MainApp = connect(mapStateToProps, mapDispatchToProps)((props: any) => {
const fetchAndSetCountry = async (coords: any) => {
const country = await getCountry({
// small helper
const fetchAndSetCountry = async (coords: Geolocation.GeoCoordinates) => {
const country: string = await getCountry({
long: coords.longitude,
lat: coords.latitude
})
props.setCountry(country)
}

// Get mobile location -> set country
useEffect(() => {
// some bug in react native
setTimeout(() => {
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)
GeolocationPermissions()
.then(() => {
Geolocation.getCurrentPosition(
(pos) => fetchAndSetCountry(pos.coords),
(err) => {
console.log('Error Getting Position:', err.message)
fetchAndSetCountry(INDIA)
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
)
})
.catch((err) => console.log('MainApp -> UseEffect -> Location Error:', err.message))
}, [])

// if mobile location set -> get covid stats
useEffect(() => {
if (props.country !== null) {
getCovidData(props.country)
Expand All @@ -116,7 +88,7 @@ const MainApp = connect(mapStateToProps, mapDispatchToProps)((props: any) => {
}
}, [props.country])

// this useEffect should hide all implementation of splash screen from native and web
// hide all implementation of splash screen from native and web
useEffect(() => {
if (props.data?.global !== undefined) {
hideAsync()
Expand Down
17 changes: 2 additions & 15 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ android {
applicationId "com.covid19"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2
versionName "3.0.0"
versionCode 3
versionName "3.1.1"
}
splits {
abi {
Expand Down Expand Up @@ -200,19 +200,6 @@ dependencies {
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

addUnimodulesDependencies()

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}

debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}

if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
Expand Down
72 changes: 0 additions & 72 deletions android/app/src/debug/java/com/covid19/ReactNativeFlipper.java

This file was deleted.

32 changes: 0 additions & 32 deletions android/app/src/main/java/com/covid19/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,5 @@ public ReactNativeHost getReactNativeHost() {
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}

/**
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
*
* @param context
* @param reactInstanceManager
*/
private static void initializeFlipper(
Context context, ReactInstanceManager reactInstanceManager) {
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.covid19.ReactNativeFlipper");
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
.invoke(null, context, reactInstanceManager);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
3 changes: 0 additions & 3 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.54.0

org.gradle.jvmargs=-Xmx4608M
Loading

0 comments on commit 146afa5

Please sign in to comment.