From 98fae0376eea9e10af8b31055b4e35fe2fe6deff Mon Sep 17 00:00:00 2001 From: Ren Juan Date: Wed, 18 Aug 2021 18:21:15 +0000 Subject: [PATCH] * --- Ejectable/App.tsx | 43 ++++++- Ejectable/GT2Service.js | 42 ------- Ejectable/components/ScreenInfo.tsx | 13 ++- Ejectable/navigation/BottomTabNavigator.tsx | 12 +- Ejectable/screens/TripScreen.tsx | 120 ++++++++++++++++---- Ejectable/types.tsx | 1 + README.md | 3 + 7 files changed, 157 insertions(+), 77 deletions(-) delete mode 100644 Ejectable/GT2Service.js diff --git a/Ejectable/App.tsx b/Ejectable/App.tsx index cf33a65d..8b17bbfa 100644 --- a/Ejectable/App.tsx +++ b/Ejectable/App.tsx @@ -1,27 +1,64 @@ import 'react-native-gesture-handler'; import { StatusBar } from 'expo-status-bar'; -import React, { useState } from 'react'; -import Switch from 'react-native'; +import React, { useState, useEffect } from 'react'; +import { Platform, Text, View, Switch, StyleSheet } from 'react-native'; +import * as Location from 'expo-location'; import { SafeAreaProvider } from 'react-native-safe-area-context'; - import useCachedResources from './hooks/useCachedResources'; import useColorScheme from './hooks/useColorScheme'; import Navigation from './navigation'; +export var debug:boolean = false; +export var expoGeoState:any; +export var tripInProgress:boolean = true; + export default function App() { const isLoadingComplete = useCachedResources(); const colorScheme = useColorScheme(); const [isKM, setIsKM] = useState(false); const toggleUnits = () => setIsKM(previousState => !previousState); + const [location, setLocation] = useState(Object); + const [errorMsg, setErrorMsg] = useState(""); + + useEffect(() => { + (async () => { + let { status } = await Location.requestForegroundPermissionsAsync(); + if (status !== 'granted') { + setErrorMsg('Permission to access location was denied'); + return; + } + + let location = await Location.getCurrentPositionAsync({}); + setLocation(location); + })(); + }, []); + + expoGeoState = 'Waiting..'; + if (errorMsg) { + expoGeoState = errorMsg; + } else if (location) { + expoGeoState = JSON.stringify(location); + } if (!isLoadingComplete) { return null; } else { + if (!debug) return ( ); + else + return ( + + + {expoGeoState} + + + ); } } + +export function toggleTripInProgress() {tripInProgress = !tripInProgress;} \ No newline at end of file diff --git a/Ejectable/GT2Service.js b/Ejectable/GT2Service.js deleted file mode 100644 index 8d8dd547..00000000 --- a/Ejectable/GT2Service.js +++ /dev/null @@ -1,42 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import { Platform, Text, View, StyleSheet } from 'react-native'; -import * as Location from 'expo-location'; - -export class GT2Service { - - constructor () { - const [location, setLocation] = useState(null); - const [errorMsg, setErrorMsg] = useState(null); - - } - - start() { - - useEffect(() => { - (async () => { - let { status } = await Location.requestForegroundPermissionsAsync(); - if (status !== 'granted') { - setErrorMsg('Permission to access location was denied'); - return; - } - - let location = await Location.getCurrentPositionAsync({}); - setLocation(location); - })(); - }, []); - - let text = 'Waiting..'; - if (errorMsg) { - text = errorMsg; - } else if (location) { - text = JSON.stringify(location); - } - - return ( - - {text} - - ); - } - -} diff --git a/Ejectable/components/ScreenInfo.tsx b/Ejectable/components/ScreenInfo.tsx index 4154b13f..2d0b4839 100644 --- a/Ejectable/components/ScreenInfo.tsx +++ b/Ejectable/components/ScreenInfo.tsx @@ -38,7 +38,13 @@ export function ScreenInfo3() { style={styles.settingsText} lightColor="rgba(0,0,0,0.8)" darkColor="rgba(255,255,255,0.8)"> - Green Travel Carbon Calculator v. 2 + Green Travel Carbon Calculator v. 2 + + + expo version ); @@ -54,5 +60,8 @@ const styles = StyleSheet.create({ lineHeight: 24, textAlign: 'center', }, - + versionText: { + fontSize: 8, + textAlign: 'center', + }, }); diff --git a/Ejectable/navigation/BottomTabNavigator.tsx b/Ejectable/navigation/BottomTabNavigator.tsx index 83b9e690..a8b748be 100644 --- a/Ejectable/navigation/BottomTabNavigator.tsx +++ b/Ejectable/navigation/BottomTabNavigator.tsx @@ -7,15 +7,14 @@ import { Ionicons } from '@expo/vector-icons'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { createStackNavigator } from '@react-navigation/stack'; import * as React from 'react'; - import Colors from '../constants/Colors'; import useColorScheme from '../hooks/useColorScheme'; import SplashScreen from '../screens/SplashScreen'; -import TripScreen from '../screens/TripScreen'; import SettingsScreen from '../screens/SettingsScreen'; +import TripScreen from '../screens/TripScreen'; import { SplashParamList, BottomTabParamList, TripParamList, SettingsParamList } from '../types'; -const BottomTab = createBottomTabNavigator(); +export const BottomTab = createBottomTabNavigator(); export default function BottomTabNavigator() { const colorScheme = useColorScheme(); @@ -25,7 +24,7 @@ export default function BottomTabNavigator() { initialRouteName="Splash" tabBarOptions={{ activeTintColor: Colors[colorScheme].tint }}> , @@ -57,8 +56,7 @@ function TabBarIcon(props: { name: React.ComponentProps['name'] // Each tab has its own navigation stack, you can read more about this pattern here: // https://reactnavigation.org/docs/tab-based-navigation#a-stack-navigator-for-each-tab -const SplashStack = createStackNavigator(); -const TripStack = createStackNavigator(); +const SplashStack = createStackNavigator(); function SplashNavigator() { return ( @@ -72,6 +70,8 @@ function SplashNavigator() { ); } +const TripStack = createStackNavigator(); + function TripNavigator() { return ( diff --git a/Ejectable/screens/TripScreen.tsx b/Ejectable/screens/TripScreen.tsx index 91147b71..04437e00 100644 --- a/Ejectable/screens/TripScreen.tsx +++ b/Ejectable/screens/TripScreen.tsx @@ -1,34 +1,24 @@ import * as React from 'react'; +import { Component } from 'react'; import { Button, StyleSheet, Alert } from 'react-native'; import { Text, View } from '../components/Themed'; -import { GT2Service } from '../GT2Service.js'; import { ScreenInfo2 } from '../components/ScreenInfo'; +import { geocodeAsync } from 'expo-location'; +import * as GT2 from '../App'; +import * as Nav from '../navigation/BottomTabNavigator'; +import Navigation from '../navigation'; -export default function TripScreen() { - return ( - - Trip Control - - - -