Merge pull request #4 from lemeow125/feature/location

Fixed button and text input styling and improved homepage
This commit is contained in:
lemeow125 2023-07-07 18:10:36 +08:00 committed by GitHub
commit 8b537658f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 20 deletions

19
package-lock.json generated
View file

@ -16,6 +16,7 @@
"@tanstack/react-query": "^4.29.19", "@tanstack/react-query": "^4.29.19",
"axios": "^1.4.0", "axios": "^1.4.0",
"expo": "~48.0.18", "expo": "~48.0.18",
"expo-intent-launcher": "~10.5.2",
"expo-linking": "~4.0.1", "expo-linking": "~4.0.1",
"expo-location": "~15.1.1", "expo-location": "~15.1.1",
"expo-status-bar": "~1.4.4", "expo-status-bar": "~1.4.4",
@ -24,7 +25,7 @@
"react-native": "0.71.8", "react-native": "0.71.8",
"react-native-dropdown-picker": "^5.4.6", "react-native-dropdown-picker": "^5.4.6",
"react-native-gesture-handler": "~2.9.0", "react-native-gesture-handler": "~2.9.0",
"react-native-maps": "^1.7.1", "react-native-maps": "1.3.2",
"react-native-reanimated": "~2.14.4", "react-native-reanimated": "~2.14.4",
"react-native-safe-area-context": "4.5.0", "react-native-safe-area-context": "4.5.0",
"react-native-screens": "~3.20.0", "react-native-screens": "~3.20.0",
@ -7418,6 +7419,14 @@
"expo": "*" "expo": "*"
} }
}, },
"node_modules/expo-intent-launcher": {
"version": "10.5.2",
"resolved": "https://registry.npmjs.org/expo-intent-launcher/-/expo-intent-launcher-10.5.2.tgz",
"integrity": "sha512-qFIanCkLlTvqYTtJQJocZuZesi6b8lAdY9xF3oLFsdaTXKIMrfQfWI67zwBJvaNqgiV9MbbYnBHsFoOAzhBTKA==",
"peerDependencies": {
"expo": "*"
}
},
"node_modules/expo-keep-awake": { "node_modules/expo-keep-awake": {
"version": "12.0.1", "version": "12.0.1",
"resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-12.0.1.tgz", "resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-12.0.1.tgz",
@ -12243,11 +12252,11 @@
"integrity": "sha512-1dVk9NwhoyKHCSxcrM6vY6cxmojeATsBobDicX0ZKr7DgUF2cBQRTKsimQFvzH8XhOVXyH8p4HyDSZNIFI8OlQ==" "integrity": "sha512-1dVk9NwhoyKHCSxcrM6vY6cxmojeATsBobDicX0ZKr7DgUF2cBQRTKsimQFvzH8XhOVXyH8p4HyDSZNIFI8OlQ=="
}, },
"node_modules/react-native-maps": { "node_modules/react-native-maps": {
"version": "1.7.1", "version": "1.3.2",
"resolved": "https://registry.npmjs.org/react-native-maps/-/react-native-maps-1.7.1.tgz", "resolved": "https://registry.npmjs.org/react-native-maps/-/react-native-maps-1.3.2.tgz",
"integrity": "sha512-CHVLzL+Q2jiUGgbt4/vosxVI1SukWyaLGjD62VLgR/wZpnH4Umi9ql1bmKDPWcfj2C1QZwMU0Yc7rXTbvZUIiw==", "integrity": "sha512-NB7HGRZOgxxXCWzrhIVucx/bsrEWANvk3DLci1ov4P9MQnEVQYQCCkTxsnaEvO191GeBOCRDyYn6jckqbfMtmg==",
"dependencies": { "dependencies": {
"@types/geojson": "^7946.0.10" "@types/geojson": "^7946.0.8"
}, },
"peerDependencies": { "peerDependencies": {
"react": ">= 17.0.1", "react": ">= 17.0.1",

View file

@ -17,6 +17,7 @@
"@tanstack/react-query": "^4.29.19", "@tanstack/react-query": "^4.29.19",
"axios": "^1.4.0", "axios": "^1.4.0",
"expo": "~48.0.18", "expo": "~48.0.18",
"expo-intent-launcher": "~10.5.2",
"expo-linking": "~4.0.1", "expo-linking": "~4.0.1",
"expo-location": "~15.1.1", "expo-location": "~15.1.1",
"expo-status-bar": "~1.4.4", "expo-status-bar": "~1.4.4",
@ -25,13 +26,13 @@
"react-native": "0.71.8", "react-native": "0.71.8",
"react-native-dropdown-picker": "^5.4.6", "react-native-dropdown-picker": "^5.4.6",
"react-native-gesture-handler": "~2.9.0", "react-native-gesture-handler": "~2.9.0",
"react-native-maps": "^1.7.1",
"react-native-reanimated": "~2.14.4", "react-native-reanimated": "~2.14.4",
"react-native-safe-area-context": "4.5.0", "react-native-safe-area-context": "4.5.0",
"react-native-screens": "~3.20.0", "react-native-screens": "~3.20.0",
"react-native-svg": "13.4.0", "react-native-svg": "13.4.0",
"react-redux": "^8.1.1", "react-redux": "^8.1.1",
"redux": "^4.2.1" "redux": "^4.2.1",
"react-native-maps": "1.3.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.20.0", "@babel/core": "^7.20.0",

View file

@ -23,7 +23,6 @@ export default function Button({ disabled = false, ...props }: props) {
? `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, 0.3)` ? `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, 0.3)`
: "rgba(0, 0, 0, 0)" : "rgba(0, 0, 0, 0)"
: props.color, : props.color,
width: "50%",
}, },
}} }}
> >

View file

@ -9,19 +9,27 @@ import * as Location from "expo-location";
import GetDistance from "../../components/GetDistance/GetDistance"; import GetDistance from "../../components/GetDistance/GetDistance";
import Button from "../../components/Button/Button"; import Button from "../../components/Button/Button";
import { colors } from "../../styles"; import { colors } from "../../styles";
import { startActivityAsync, ActivityAction } from "expo-intent-launcher";
type LocationType = Location.LocationObject; type LocationType = Location.LocationObject;
export default function Home() { export default function Home() {
const [location, setLocation] = useState<LocationType | null>(null); const [location, setLocation] = useState<LocationType | null>(null);
const [dist, setDist] = useState<number | null>(null); const [dist, setDist] = useState<number | null>(null);
const [feedback, setFeedback] = useState(
"To continue, please allow Stud-E permission to location services"
);
async function requestLocation() { async function requestLocation() {
let { status } = await Location.requestForegroundPermissionsAsync(); let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") { if (status === "granted") {
console.error("Permission to access location was denied");
return;
} else {
getLocation(); getLocation();
return;
} else if (status === "denied") {
setFeedback("Stud-E requires location services to function");
setTimeout(() => {
startActivityAsync(ActivityAction.LOCATION_SOURCE_SETTINGS);
}, 3000);
console.log("Location Permission denied");
} }
} }
@ -39,6 +47,7 @@ export default function Home() {
useEffect(() => { useEffect(() => {
requestLocation(); requestLocation();
}, []); }, []);
const ustpCoords = { const ustpCoords = {
latitude: 8.4857, latitude: 8.4857,
longitude: 124.6565, longitude: 124.6565,
@ -77,21 +86,19 @@ export default function Home() {
}} }}
/> />
<Text style={styles.text_white_small}> <Text style={styles.text_white_small}>
You are {dist}km away from USTP {"\n"} {dist}km away from USTP {"\n"}
</Text> </Text>
</View> </View>
); );
} }
} else { } else {
return ( return (
<View> <AnimatedContainer>
<Text style={styles.text_white_medium}> <Text style={styles.text_white_medium}>{feedback}</Text>
Please allow location permission{"\n"}
</Text>
<Button onPress={() => requestLocation()} color={colors.blue_3}> <Button onPress={() => requestLocation()} color={colors.blue_3}>
<Text style={styles.text_white_small}>Register</Text> <Text style={styles.text_white_small}>Allow Access</Text>
</Button> </Button>
</View> </AnimatedContainer>
); );
} }
} }

View file

@ -88,19 +88,21 @@ const styles = StyleSheet.create({
justifyContent: "center", justifyContent: "center",
alignSelf: "center", alignSelf: "center",
alignItems: "center", alignItems: "center",
textAlign: "center",
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
marginVertical: 4, marginVertical: 4,
marginHorizontal: 8, marginHorizontal: 8,
padding: 8, padding: 8,
borderRadius: 16, borderRadius: 16,
width: width * 0.4,
}, },
text_input: { text_input: {
color: colors.text_default, color: colors.text_default,
backgroundColor: colors.blue_1, backgroundColor: colors.blue_1,
width: "50%",
padding: 10, padding: 10,
borderRadius: 8, borderRadius: 8,
width: width * 0.5,
}, },
dropdown_template: { dropdown_template: {
borderRadius: 16, borderRadius: 16,