This commit is contained in:
Ren Juan 2021-08-24 07:57:21 +00:00
parent 651793bfe2
commit 13887bcbda
7 changed files with 63 additions and 8 deletions

34
Ejectable/ExpoTaskMgr.js Normal file
View File

@ -0,0 +1,34 @@
import React from 'react';
import { Text, TouchableOpacity } from 'react-native';
import * as TaskManager from 'expo-task-manager';
import * as Location from 'expo-location';
const LOCATION_TASK_NAME = 'background-location-task';
const requestPermissions = async () => {
const { status } = await Location.requestBackgroundPermissionsAsync();
if (status === 'granted') {
await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
accuracy: Location.Accuracy.Balanced,
});
}
};
const PermissionsButton = () => (
<TouchableOpacity onPress={requestPermissions}>
<Text>Enable background location</Text>
</TouchableOpacity>
);
TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => {
if (error) {
// Error occurred - check `error.message` for more details.
return;
}
if (data) {
const { locations } = data;
// do something with the locations captured in the background
}
});
export default PermissionsButton;

View File

@ -170,7 +170,6 @@ export class GT2 {
public reset() { public reset() {
this.distance = 0.0; this.distance = 0.0;
this.co2Rate = 0.0;
this.endPoint = new Coordinate(0,0); this.endPoint = new Coordinate(0,0);
this.startPoint = new Coordinate(0,0); this.startPoint = new Coordinate(0,0);
this.v = 0; this.v = 0;

View File

@ -19,7 +19,13 @@
"**/*" "**/*"
], ],
"ios": { "ios": {
"supportsTablet": true "supportsTablet": true,
"infoPlist": {
"UIBackgroundModes": [
"location",
"fetch"
]
}
}, },
"android": { "android": {
"adaptiveIcon": { "adaptiveIcon": {

View File

@ -6142,6 +6142,16 @@
"resolved": "https://registry.npmjs.org/expo-status-bar/-/expo-status-bar-1.0.4.tgz", "resolved": "https://registry.npmjs.org/expo-status-bar/-/expo-status-bar-1.0.4.tgz",
"integrity": "sha512-s7nc496D/Zn1NGiMJ5wu6HyIdXxbgGtmZZtbHm7rpbcmLdf28GmMSNHDx7M0t00BMhky7VAurTCUo+BJs8ugsw==" "integrity": "sha512-s7nc496D/Zn1NGiMJ5wu6HyIdXxbgGtmZZtbHm7rpbcmLdf28GmMSNHDx7M0t00BMhky7VAurTCUo+BJs8ugsw=="
}, },
"expo-task-manager": {
"version": "9.2.2",
"resolved": "https://registry.npmjs.org/expo-task-manager/-/expo-task-manager-9.2.2.tgz",
"integrity": "sha512-GDObZYoCT1bwYXYtT9RinRhR7Y+mCy6DvO7OvRFW3hgxHVXvAM8YFA8jr3airY0XF73aT35/nFnOe+MFCELXFA==",
"requires": {
"@expo/config-plugins": "^3.0.0",
"expo-modules-core": "~0.2.0",
"unimodules-app-loader": "~2.2.0"
}
},
"expo-web-browser": { "expo-web-browser": {
"version": "9.2.0", "version": "9.2.0",
"resolved": "https://registry.npmjs.org/expo-web-browser/-/expo-web-browser-9.2.0.tgz", "resolved": "https://registry.npmjs.org/expo-web-browser/-/expo-web-browser-9.2.0.tgz",
@ -15002,6 +15012,11 @@
"resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.1.0.tgz", "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.1.0.tgz",
"integrity": "sha512-PqSoPh/pWetQ2phoj5RLiaqIk4kCNwoV3CI+LfGmWLKI3rE3kl1h59XpX2BjgDrmbxD9ARtQobPGU1SguCYuQg==" "integrity": "sha512-PqSoPh/pWetQ2phoj5RLiaqIk4kCNwoV3CI+LfGmWLKI3rE3kl1h59XpX2BjgDrmbxD9ARtQobPGU1SguCYuQg=="
}, },
"unimodules-app-loader": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/unimodules-app-loader/-/unimodules-app-loader-2.2.0.tgz",
"integrity": "sha512-porQWVWu7meIrCJ+c+H7eJyeC2rHioLUZiv4UcOs33SAyUhR4X05tCC8NIOuQJsF08Fj3a0ck7HUsd5xq+LqKA=="
},
"union-value": { "union-value": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",

View File

@ -33,7 +33,8 @@
"react-native-reanimated": "~2.2.0", "react-native-reanimated": "~2.2.0",
"react-native-safe-area-context": "3.2.0", "react-native-safe-area-context": "3.2.0",
"react-native-screens": "~3.4.0", "react-native-screens": "~3.4.0",
"react-native-web": "~0.13.12" "react-native-web": "~0.13.12",
"expo-task-manager": "~9.2.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.9.0", "@babel/core": "^7.9.0",

View File

@ -36,7 +36,7 @@ export default function SettingsScreen() {
<Button <Button
title="Gasoline" title="Gasoline"
onPress={() => { onPress={() => {
Trips.co2Rate = 285.0; Trips.co2Rate = 255.0;
Trips.CO2Effect = "carbon burden"; Trips.CO2Effect = "carbon burden";
Alert.alert('Gasoline Selected \n 255 g for driver \n only passenger / km')} Alert.alert('Gasoline Selected \n 255 g for driver \n only passenger / km')}
} }
@ -44,7 +44,7 @@ export default function SettingsScreen() {
<Button <Button
title="Food" title="Food"
onPress={() => { onPress={() => {
Trips.co2Rate = -285.0; Trips.co2Rate = -255.0;
Trips.CO2Effect = "carbon relief"; Trips.CO2Effect = "carbon relief";
Alert.alert('Savings vs Gasoline Selected')} Alert.alert('Savings vs Gasoline Selected')}
} }

View File

@ -1,6 +1,6 @@
import * as React from 'react'; import * as React from 'react';
import { useState } from 'react'; import { useState } from 'react';
import { Alert, Button, StyleSheet } from 'react-native'; import { Alert, BackHandler, Button, StyleSheet } from 'react-native';
import { Text, View } from '../components/Themed'; import { Text, View } from '../components/Themed';
import { ScreenInfo2 } from '../components/ScreenInfo'; import { ScreenInfo2 } from '../components/ScreenInfo';
import EndScreenInfo from '../components/EndScreenInfo'; import EndScreenInfo from '../components/EndScreenInfo';
@ -55,7 +55,7 @@ function pauseTrip() {
function endTrip() { Trips.end(); } function endTrip() { Trips.end(); }
export default function TripScreen( navigation:any ) { export default function TripScreen( ) {
const [sButtonText, setSButtonText] = useState("Start"); const [sButtonText, setSButtonText] = useState("Start");
const [pButtonText, setPButtonText] = useState("Pause"); const [pButtonText, setPButtonText] = useState("Pause");
@ -92,7 +92,7 @@ export default function TripScreen( navigation:any ) {
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" /> <View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
<EndScreenInfo path="/screens/TripScreen.tsx" /> <EndScreenInfo path="/screens/TripScreen.tsx" />
<Button title={'Dismiss'} <Button title={'Dismiss'}
onPress={() => { toggleEndPending(); if (getEndPending()) Alert.alert("t"); else Alert.alert("f"); }} onPress={() => { toggleEndPending(); }}
/> />
</View> </View>
); );