GT2/Ejectable/screens/SettingsScreen.tsx

141 lines
3.8 KiB
TypeScript
Raw Permalink Normal View History

2021-08-16 07:50:50 +00:00
import * as React from 'react';
2021-08-17 21:05:34 +00:00
import { Alert, Button, StyleSheet, Switch, TextInput } from 'react-native';
2021-08-16 07:50:50 +00:00
import { Text, View } from '../components/Themed';
2021-08-16 22:39:34 +00:00
import { useState } from 'react';
2021-08-28 02:34:15 +00:00
import ScreenInfo, { ScreenInfo4, ScreenInfo5 } from '../components/ScreenInfo';
2021-08-24 00:02:21 +00:00
import { Trips } from '../GT2';
2021-08-24 15:43:25 +00:00
import { RootTabScreenProps } from '../types';
2021-08-16 07:50:50 +00:00
2021-08-28 02:34:15 +00:00
2021-08-24 15:43:25 +00:00
export default function SettingsScreen( { navigation }: RootTabScreenProps<'Settings'>) {
2021-08-28 02:34:15 +00:00
const [rate, setRate] = useState("255");
const [sens, setSens] = useState("3");
2021-08-17 21:05:34 +00:00
const [isKM, setMiles] = useState(false);
2021-08-25 02:25:04 +00:00
const toggleUnits = () => { setMiles(previousState => !previousState)
Trips.units = isKM ? "km" : "mi";
};
2021-08-16 07:50:50 +00:00
return (
<View style={styles.container}>
<Text style={styles.title}>Model Settings</Text>
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
2021-08-28 03:34:05 +00:00
<View style={styles.captions}>
<Text style={styles.caption}>CO2 / km</Text>
<Text>{' '}</Text>
<Text style={styles.caption}>sensitivity</Text>
</View>
2021-08-28 02:34:15 +00:00
<View style={styles.inputs}>
<TextInput
style={styles.input}
returnKeyType={'done'}
onChangeText={rate => { setRate(rate); Trips.co2Rate = Number(rate);} }
value={rate}
placeholder={Trips.co2Rate.toString()}
keyboardType="numeric"
2021-08-28 03:34:05 +00:00
/>
2021-08-28 02:34:15 +00:00
<TextInput
style={styles.input}
returnKeyType={'done'}
onChangeText={sens => { setSens(sens);
var s = Number(sens);
if (s < 3 || s > 7) Alert.alert("Sensitivity must be greater than 2 and less than 8");
else Trips.sensitivity = Number(sens); }}
value={sens}
placeholder={Trips.sensitivity.toString()}
keyboardType="numeric"
2021-08-28 03:34:05 +00:00
/>
2021-08-28 02:34:15 +00:00
</View>
<ScreenInfo4/>
2021-08-17 21:05:34 +00:00
<View style={styles.controls} >
<Button
title="Jet"
2021-08-24 00:02:21 +00:00
onPress={() => {
Trips.co2Rate = 285.0;
Trips.CO2Effect = "carbon burden";
Alert.alert('Jet Fuel Selected \n 285 g / passenger / km')}
}
2021-08-17 21:05:34 +00:00
/>
<Button
title="Gasoline"
2021-08-24 00:02:21 +00:00
onPress={() => {
2021-08-24 07:57:21 +00:00
Trips.co2Rate = 255.0;
2021-08-24 00:02:21 +00:00
Trips.CO2Effect = "carbon burden";
Alert.alert('Gasoline Selected \n 255 g for driver \n only passenger / km')}
}
2021-08-17 21:05:34 +00:00
/>
<Button
title="Food"
2021-08-24 00:02:21 +00:00
onPress={() => {
2021-08-24 07:57:21 +00:00
Trips.co2Rate = -255.0;
2021-08-24 00:02:21 +00:00
Trips.CO2Effect = "carbon relief";
Alert.alert('Savings vs Gasoline Selected')}
}
2021-08-17 21:05:34 +00:00
/>
</View>
2021-08-28 02:34:15 +00:00
<ScreenInfo />
<Switch
style={styles.switch}
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={true ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleUnits}
value={isKM}
/>
2021-08-16 07:50:50 +00:00
</View>
);
}
2021-08-17 21:05:34 +00:00
2021-08-16 07:50:50 +00:00
const styles = StyleSheet.create({
2021-08-28 02:34:15 +00:00
caption: {
fontSize: 10,
justifyContent: 'center',
},
2021-08-17 21:05:34 +00:00
switch: {
2021-08-28 03:34:05 +00:00
marginVertical: 2,
2021-08-17 21:05:34 +00:00
},
2021-08-16 07:50:50 +00:00
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
2021-08-17 21:05:34 +00:00
controls: {
2021-08-28 02:34:15 +00:00
marginVertical: 5,
2021-08-17 21:05:34 +00:00
width: "80%",
flexDirection: 'row',
justifyContent: "space-between",
},
2021-08-28 03:34:05 +00:00
captions: {
marginVertical: 15,
width: "90%",
flexDirection: 'row',
justifyContent: "center"
},
2021-08-28 02:34:15 +00:00
inputs: {
2021-08-28 03:34:05 +00:00
marginVertical: -20,
2021-08-28 02:34:15 +00:00
width: "80%",
flexDirection: 'row',
justifyContent: "center",
},
2021-08-16 07:50:50 +00:00
title: {
fontSize: 20,
fontWeight: 'bold',
},
separator: {
2021-08-28 02:34:15 +00:00
marginVertical: 2,
2021-08-16 07:50:50 +00:00
height: 1,
width: '80%',
},
2021-08-16 22:39:34 +00:00
input: {
height: 40,
2021-08-28 03:34:05 +00:00
margin: 10,
2021-08-16 22:39:34 +00:00
borderWidth: 1,
padding: 10,
},
2021-08-28 02:34:15 +00:00
input2: {
height: 40,
margin: 30,
borderWidth: 1,
padding: 10,
},
2021-08-16 07:50:50 +00:00
});