Skip to content

Commit

Permalink
Sing Out Button and Map
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanCheungJF committed Jan 8, 2022
1 parent 6bd96d7 commit bfc0c4c
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ web-build/
# macOS
.DS_Store

/firebase.js
secrets.json
3 changes: 3 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import HomeScreen from "./src/screens/HomeScreen";
import LoginScreen from "./src/screens/LoginScreen";
import MapScreen from "./src/screens/MapScreen";

export type RootStackParamList = {
Home: undefined;
Login: undefined;
Map: undefined;
};

const Stack = createNativeStackNavigator<RootStackParamList>();
Expand All @@ -18,6 +20,7 @@ const App = () => {
<Stack.Navigator>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Map" component={MapScreen} />
</Stack.Navigator>
</NavigationContainer>
);
Expand Down
1 change: 1 addition & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Developer Guide
12 changes: 12 additions & 0 deletions firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import secrets from "./secrets.json";

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = secrets.firebase;

// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig);

export const auth = getAuth(firebaseApp);
7 changes: 7 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>For users to see their current location when completing our amazing race.</string>
</dict>
</plist>
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
"eject": "expo eject"
},
"dependencies": {
"@react-native-community/geolocation": "^2.0.2",
"@react-navigation/native": "^6.0.6",
"@react-navigation/native-stack": "^6.2.5",
"expo": "~44.0.0",
"expo-cli": "^5.0.1",
"expo-location": "~14.0.1",
"expo-permissions": "~13.1.0",
"expo-status-bar": "~1.2.0",
"firebase": "^9.6.1",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-geolocation-service": "^5.3.0-beta.4",
"react-native-maps": "0.29.4",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.10.1",
"react-native-web": "0.17.1"
Expand Down
85 changes: 78 additions & 7 deletions src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import {
KeyboardAvoidingView,
StyleSheet,
Text,
TouchableOpacity,
View,
} from "react-native";
import { useNavigation } from "@react-navigation/native";
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { signOut } from "firebase/auth";
import { auth } from "../../firebase";
import { RootStackParamList } from "../../App";

type logoutScreenNavigationType = NativeStackNavigationProp<
RootStackParamList,
"Home"
>;

const HomeScreen = () => {
const navigation = useNavigation<logoutScreenNavigationType>();

const logoutHandler = () => {
signOut(auth)
.then(() => {
navigation.replace("Login");
})
.catch((err) => console.log(err));
};

const mapHandler = () => {
navigation.replace("Map");
}

function HomeScreen() {
return (
<View style={styles.container}>
<Text>Congratluations! You managed to log in! Happy coding c:</Text>
</View>
<KeyboardAvoidingView style={styles.container} behavior="padding">
<Text>
You are logged in as{" "}
{auth.currentUser ? auth.currentUser.email : "ERROR"}!
</Text>
<View style={styles.buttonContainer}>
<TouchableOpacity onPress={logoutHandler} style={styles.button}>
<Text style={styles.buttonText}>Logout</Text>
</TouchableOpacity>
</View>
<View style={styles.buttonContainer}>
<TouchableOpacity onPress={mapHandler} style={styles.button}>
<Text style={styles.buttonText}>View your Current Location!</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
);
}
};

const styles = StyleSheet.create({
container: {
Expand All @@ -16,6 +58,35 @@ const styles = StyleSheet.create({
alignItems: "center",
justifyContent: "center",
},
buttonContainer: {
width: "60%",
justifyContent: "center",
alignItems: "center",
marginTop: 40,
},
button: {
backgroundColor: "#0782F9",
width: "100%",
padding: 15,
borderRadius: 10,
alignItems: "center",
},
buttonOutline: {
backgroundColor: "white",
marginTop: 5,
borderColor: "#0782F9",
borderWidth: 2,
},
buttonText: {
color: "white",
fontWeight: "700",
fontSize: 16,
},
buttonOutlineText: {
color: "#0782F9",
fontWeight: "700",
fontSize: 16,
},
});

export default HomeScreen;
9 changes: 6 additions & 3 deletions src/screens/LoginScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import { useEffect, useState } from "react";
import {
KeyboardAvoidingView,
View,
Expand All @@ -17,7 +17,10 @@ import {
import { auth } from "../../firebase";
import { RootStackParamList } from "../../App";

type loginScreenNavigationType = NativeStackNavigationProp<RootStackParamList, "Login">
type loginScreenNavigationType = NativeStackNavigationProp<
RootStackParamList,
"Login"
>;

const LoginScreen = () => {
const [email, setEmail] = useState("");
Expand All @@ -28,7 +31,7 @@ const LoginScreen = () => {
useEffect(() => {
const onListener = onAuthStateChanged(auth, (user) => {
if (user) {
navigation.navigate('Home');
navigation.navigate("Home");
}
});
return onListener;
Expand Down
73 changes: 73 additions & 0 deletions src/screens/MapScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { useEffect, useState } from "react";
import MapView from "react-native-maps";
import { StyleSheet, Text, View, Dimensions } from "react-native";
import * as Location from "expo-location";

interface Region {
latitude: number;
longitude: number;
latitudeDelta: number;
longitudeDelta: number;
}

const sentosaDefault: Region = {
latitude: 1.254206,
longitude: 103.819977,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
};

const MapScreen = () => {
const [loading, setLoading] = useState(true);
const [region, setRegion] = useState(sentosaDefault);

useEffect(() => {
(async () => {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") {
alert("Permission Denied!");
return;
}
let location = await Location.getCurrentPositionAsync();
console.log(location);
const r = {
latitude: location.coords.latitude,
longitude: location.coords.longitude,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
};
setRegion(r);
setLoading(false);
})();
}, []);

if (loading) {
return <Text>loading...</Text>;
} else {
return (
<View style={styles.container}>
<MapView
style={styles.map}
provider={"google"}
initialRegion={region}
showsUserLocation={true}
/>
</View>
);
}
};

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
map: {
width: Dimensions.get("window").width,
height: Dimensions.get("window").height,
},
});

export default MapScreen;
40 changes: 40 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,11 @@
sudo-prompt "^9.0.0"
wcwidth "^1.0.1"

"@react-native-community/geolocation@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@react-native-community/geolocation/-/geolocation-2.0.2.tgz#ba8b40f560ead8d014740d1cdea970b33f19312e"
integrity sha512-tTNXRCgnhJBu79mulQwzabXRpDqfh/uaDqfHVpvF0nX4NTpolpy6mvTRiFg7eWFPGRArsnZz1EYp6rHfJWGgEA==

"@react-native/[email protected]":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@react-native/assets/-/assets-1.0.0.tgz#c6f9bf63d274bafc8e970628de24986b30a55c8e"
Expand Down Expand Up @@ -2277,6 +2282,11 @@
"@types/node" "*"
"@types/responselike" "*"

"@types/geojson@^7946.0.7":
version "7946.0.8"
resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.8.tgz#30744afdb385e2945e22f3b033f897f76b1f12ca"
integrity sha512-1rkryxURpr6aWP7R786/UQOkJ3PcpQiWkAXBmdWc7ryFWqN6a4xfK7BtjXvFBKO9LjQ+MWQSWxYeZX1OApnArA==

"@types/glob@^7.1.1":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
Expand Down Expand Up @@ -5319,6 +5329,14 @@ expo-keep-awake@~10.0.1:
resolved "https://registry.yarnpkg.com/expo-keep-awake/-/expo-keep-awake-10.0.1.tgz#9f1176216c41eee20843c8232acfdca2bc32d334"
integrity sha512-kcBtoDGkm3RRe6BpKDvR7gof/ErajEia38u92pRvNRctdh+p8AFO7GQuiipyg3iMfhcCFVTCIV7h3tuA0g/yDw==

expo-location@~14.0.1:
version "14.0.1"
resolved "https://registry.yarnpkg.com/expo-location/-/expo-location-14.0.1.tgz#28a5ab1296a103202bb7598539cf78e2f0be5991"
integrity sha512-P3Mrty7uxezBFE9SwYhskeNwwHAapw/6lrLj2fYILgJkNiXv28ns5CwSNsTtJ+MfeHeV93t20qrkk7kJ30SQVw==
dependencies:
"@expo/config-plugins" "^4.0.2"
unimodules-task-manager-interface "~7.1.0"

[email protected]:
version "0.5.1"
resolved "https://registry.yarnpkg.com/expo-modules-autolinking/-/expo-modules-autolinking-0.5.1.tgz#44f56288d55f6a71576ddd94c18ec9ec8141207b"
Expand Down Expand Up @@ -5349,6 +5367,11 @@ [email protected]:
compare-versions "^3.4.0"
invariant "^2.2.4"

expo-permissions@~13.1.0:
version "13.1.0"
resolved "https://registry.yarnpkg.com/expo-permissions/-/expo-permissions-13.1.0.tgz#1be8fe01476950d642ea83d383fd8912492434b9"
integrity sha512-f3ngERaoeAw8236xyvw4gS89Fxd4fU2soKXQn0JPXwiDGmIXO+lIJNH3psNvAebj4DfmyQtGW4AS1itG83GHaQ==

[email protected]:
version "0.0.108"
resolved "https://registry.yarnpkg.com/expo-pwa/-/expo-pwa-0.0.108.tgz#04ab5b8a417009f5b640352c907fd33f24db4b03"
Expand Down Expand Up @@ -10203,6 +10226,18 @@ react-native-codegen@^0.0.6:
jscodeshift "^0.11.0"
nullthrows "^1.1.1"

react-native-geolocation-service@^5.3.0-beta.4:
version "5.3.0-beta.4"
resolved "https://registry.yarnpkg.com/react-native-geolocation-service/-/react-native-geolocation-service-5.3.0-beta.4.tgz#8061396f734028b0ecbf8316a2cda9179df19210"
integrity sha512-8Z/FP1ls02fnvqXCII+dDS329lP3UigNR4eIHUjPQdHu/DRGMRCpJJuj05hcq37UJL/zVVsXnPFdLA9lCOWYCQ==

[email protected]:
version "0.29.4"
resolved "https://registry.yarnpkg.com/react-native-maps/-/react-native-maps-0.29.4.tgz#eb4a446104ed2aca5361422d06712f26d4c0d562"
integrity sha512-Td2KE8+KODcHOxfB1GBNnzFo4/89rlLiC7yTvqQZh0tGVrEzIcgSleUZRrjtq/WvSWSR4rql4AS+0VsBgDkYrw==
dependencies:
"@types/geojson" "^7946.0.7"

[email protected]:
version "3.3.2"
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-3.3.2.tgz#9549a2ce580f2374edb05e49d661258d1b8bcaed"
Expand Down Expand Up @@ -12038,6 +12073,11 @@ unicode-property-aliases-ecmascript@^2.0.0:
resolved "https://registry.yarnpkg.com/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-2.0.0.tgz#0a36cb9a585c4f6abd51ad1deddb285c165297c8"
integrity sha512-5Zfuy9q/DFr4tfO7ZPeVXb1aPoeQSdeFMLpYuFebehDAhbuevLs5yxSZmIFN1tP5F9Wl4IpJrYojg85/zgyZHQ==

unimodules-task-manager-interface@~7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/unimodules-task-manager-interface/-/unimodules-task-manager-interface-7.1.0.tgz#01a981a8ff638843ce34f83a1ed73e81f62304d5"
integrity sha512-Iu6naIWWNWB69zFO6njRYj1GcfqAFnaK0hBub2zU6vvUu5A+YibZfXm5MTMq3zKfDeHrvEgVzUQszSbkjurinA==

union-value@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847"
Expand Down

0 comments on commit bfc0c4c

Please sign in to comment.