diff --git a/App.js b/App.js index 38d2bee..4afd201 100644 --- a/App.js +++ b/App.js @@ -1,33 +1,24 @@ import React from "react"; -import { StyleSheet } from "react-native"; import { Provider as PaperProvider } from "react-native-paper"; import AppContainer from "./navigation/AppNavigator"; +import { theme } from "./constants/Theme"; +import FontAwesome5 from "react-native-vector-icons/FontAwesome5"; +// TODO: Check out how to pass a theme to PaperProvider: +// https://github.com/callstack/react-native-paper-login-template/blob/master/App.tsx +// export default class App extends React.Component { render() { return ( - + + }} + theme={theme} + > ); } } - -const styles = StyleSheet.create({ - fab: { - position: "absolute", - margin: 16, - right: 0, - bottom: 0 - }, - safeAreaViewContainer: { - flex: 1 - }, - container: { - flex: 1, - backgroundColor: "#fff", - alignItems: "center", - justifyContent: "center" - }, -}); diff --git a/components/DrawerButton.js b/components/DrawerButton.js new file mode 100644 index 0000000..413fd0c --- /dev/null +++ b/components/DrawerButton.js @@ -0,0 +1,23 @@ +import * as React from "react"; +import { StyleSheet } from "react-native"; +import { FAB } from "react-native-paper"; + +const DrawerButton = props => ( + +); + +const styles = StyleSheet.create({ + fab: { + position: "absolute", + margin: 16, + left: 10, + top: 30 + } +}); + +export default DrawerButton; diff --git a/constants/Theme.js b/constants/Theme.js new file mode 100644 index 0000000..55f6b26 --- /dev/null +++ b/constants/Theme.js @@ -0,0 +1,11 @@ +import { DefaultTheme } from "react-native-paper"; + +export const theme = { + ...DefaultTheme, + colors: { + ...DefaultTheme.colors, + primary: "#600EE6", + secondary: "#414757", + error: "#f13a59" + } +}; diff --git a/navigation/AppNavigator.js b/navigation/AppNavigator.js index 217fa66..249579e 100644 --- a/navigation/AppNavigator.js +++ b/navigation/AppNavigator.js @@ -1,52 +1,9 @@ import React from 'react'; import { - SafeAreaView, createAppContainer, - createDrawerNavigator, } from "react-navigation"; -import { ScrollView } from 'react-native'; -import { Drawer } from "react-native-paper"; -import HomeScreen from "../screens/HomeScreen"; -import RoutesScreen from "../screens/RoutesScreen"; -import SignInScreen from "../screens/SignInScreen"; -import SettingsScreen from '../screens/SettingsScreen'; +import MenuDrawerNavigator from './MenuDrawerNavigator.js'; -const Menu = createDrawerNavigator( - { - Home: { screen: HomeScreen }, - Settings: { screen: SettingsScreen }, - SignIn: { screen: SignInScreen }, - Routes: { screen: RoutesScreen } - }, - { - contentComponent: props => ( - - - props.navigation.navigate("Home")} - /> - props.navigation.navigate("Settings")} - /> - props.navigation.navigate("SignIn")} - /> - props.navigation.navigate("Routes")} - /> - - - ) - } -); -export default createAppContainer(Menu); +export default createAppContainer(MenuDrawerNavigator); diff --git a/navigation/AuthNavigator.js b/navigation/AuthNavigator.js new file mode 100644 index 0000000..4f2844d --- /dev/null +++ b/navigation/AuthNavigator.js @@ -0,0 +1,25 @@ +import { createAppContainer, createSwitchNavigator } from "react-navigation"; +import { createStackNavigator } from "react-navigation-stack"; + +import HomeScreen from "../screens/HomeScreen" +import SignInScreen from "../screens/SignInScreen" +import AuthLoadingScreen from "../screens/AuthLoadingScreen" + +// Implementation of HomeScreen, OtherScreen, SignInScreen, AuthLoadingScreen +// goes here. + +const AppStack = createStackNavigator({ Home: HomeScreen, Other: OtherScreen }); +const AuthStack = createStackNavigator({ SignIn: SignInScreen }); + +export default createAppContainer( + createSwitchNavigator( + { + AuthLoading: AuthLoadingScreen, + App: AppStack, + Auth: AuthStack + }, + { + initialRouteName: "AuthLoading" + } + ) +); diff --git a/navigation/MenuDrawerNavigator.js b/navigation/MenuDrawerNavigator.js new file mode 100644 index 0000000..7dba0cf --- /dev/null +++ b/navigation/MenuDrawerNavigator.js @@ -0,0 +1,52 @@ +import React from "react"; + +import { + SafeAreaView, + createDrawerNavigator +} from "react-navigation"; +import { ScrollView } from "react-native"; +import { Drawer } from "react-native-paper"; + +import HomeScreen from "../screens/HomeScreen"; +import RoutesScreen from "../screens/RoutesScreen"; +import SignInScreen from "../screens/SignInScreen"; +import SettingsScreen from "../screens/SettingsScreen"; + + +const MenuDrawerNavigator = createDrawerNavigator( + { + Home: { screen: HomeScreen }, + Settings: { screen: SettingsScreen }, + SignIn: { screen: SignInScreen }, + Routes: { screen: RoutesScreen } + }, + { + contentComponent: props => ( + + + props.navigation.navigate("Home")} + /> + props.navigation.navigate("Settings")} + /> + props.navigation.navigate("SignIn")} + /> + props.navigation.navigate("Routes")} + /> + + + ) + } +); +export default MenuDrawerNavigator; diff --git a/screens/AuthLoadingScreen.js b/screens/AuthLoadingScreen.js new file mode 100644 index 0000000..d61084e --- /dev/null +++ b/screens/AuthLoadingScreen.js @@ -0,0 +1,35 @@ +import React from "react"; +import { + ActivityIndicator, + AsyncStorage, + StatusBar, + StyleSheet, + View +} from "react-native"; + +class AuthLoadingScreen extends React.Component { + componentDidMount() { + this._bootstrapAsync(); + } + + // Fetch the token from storage then navigate to our appropriate place + _bootstrapAsync = async () => { + const userToken = await AsyncStorage.getItem("userToken"); + + // This will switch to the App screen or Auth screen and this loading + // screen will be unmounted and thrown away. + this.props.navigation.navigate(userToken ? "App" : "Auth"); + }; + + // Render any loading content that you like here + render() { + return ( + + + + + ); + } +} + +export default AuthLoadingScreen; diff --git a/screens/HomeScreen.js b/screens/HomeScreen.js index 4d196bf..a8a5d8c 100644 --- a/screens/HomeScreen.js +++ b/screens/HomeScreen.js @@ -1,22 +1,14 @@ import React from "react"; import { View, StyleSheet } from "react-native"; -import { Appbar } from "react-native-paper"; import { Map } from "../components/Map"; +import DrawerButton from "../components/DrawerButton"; export default class HomeScreen extends React.Component { render() { return ( - - - this.props.navigation.toggleDrawer() - } - /> - - - + + this.props.navigation.toggleDrawer()} /> ); } @@ -30,189 +22,3 @@ const styles = StyleSheet.create({ justifyContent: "center" } }); - - -// export default function HomeScreen() { -// return ( -// -// -// -// -// - -// -// - -// Get started by opening - -// -// screens/HomeScreen.js -// - -// -// Change this text and your app will automatically reload. Hello world! -// -// - -// -// -// -// Help, it didn’t automatically reload! -// -// -// -// - -// -// -// This is a tab bar. You can edit it in: -// - -// -// -// navigation/MainTabNavigator.js -// -// -// -// -// ); -// } - -// HomeScreen.navigationOptions = { -// header: null, -// }; - -// function DevelopmentModeNotice() { -// if (__DEV__) { -// const learnMoreButton = ( -// -// Learn more -// -// ); - -// return ( -// -// Development mode is enabled: your app will be slower but you can use -// useful development tools. {learnMoreButton} -// -// ); -// } else { -// return ( -// -// You are not in development mode: your app will run at full speed. -// -// ); -// } -// } - -// function handleLearnMorePress() { -// WebBrowser.openBrowserAsync( -// 'https://docs.expo.io/versions/latest/workflow/development-mode/' -// ); -// } - -// function handleHelpPress() { -// WebBrowser.openBrowserAsync( -// 'https://docs.expo.io/versions/latest/workflow/up-and-running/#cant-see-your-changes' -// ); -// } - -// const styles = StyleSheet.create({ -// container: { -// flex: 1, -// backgroundColor: '#fff', -// }, -// developmentModeText: { -// marginBottom: 20, -// color: 'rgba(0,0,0,0.4)', -// fontSize: 14, -// lineHeight: 19, -// textAlign: 'center', -// }, -// contentContainer: { -// paddingTop: 30, -// }, -// welcomeContainer: { -// alignItems: 'center', -// marginTop: 10, -// marginBottom: 20, -// }, -// welcomeImage: { -// width: 100, -// height: 80, -// resizeMode: 'contain', -// marginTop: 3, -// marginLeft: -10, -// }, -// getStartedContainer: { -// alignItems: 'center', -// marginHorizontal: 50, -// }, -// homeScreenFilename: { -// marginVertical: 7, -// }, -// codeHighlightText: { -// color: 'rgba(96,100,109, 0.8)', -// }, -// codeHighlightContainer: { -// backgroundColor: 'rgba(0,0,0,0.05)', -// borderRadius: 3, -// paddingHorizontal: 4, -// }, -// getStartedText: { -// fontSize: 17, -// color: 'rgba(96,100,109, 1)', -// lineHeight: 24, -// textAlign: 'center', -// }, -// tabBarInfoContainer: { -// position: 'absolute', -// bottom: 0, -// left: 0, -// right: 0, -// ...Platform.select({ -// ios: { -// shadowColor: 'black', -// shadowOffset: { width: 0, height: -3 }, -// shadowOpacity: 0.1, -// shadowRadius: 3, -// }, -// android: { -// elevation: 20, -// }, -// }), -// alignItems: 'center', -// backgroundColor: '#fbfbfb', -// paddingVertical: 20, -// }, -// tabBarInfoText: { -// fontSize: 17, -// color: 'rgba(96,100,109, 1)', -// textAlign: 'center', -// }, -// navigationFilename: { -// marginTop: 5, -// }, -// helpContainer: { -// marginTop: 15, -// alignItems: 'center', -// }, -// helpLink: { -// paddingVertical: 15, -// }, -// helpLinkText: { -// fontSize: 14, -// color: '#2e78b7', -// }, -// }); diff --git a/screens/SignInScreen.js b/screens/SignInScreen.js index 57c8210..6a9947a 100644 --- a/screens/SignInScreen.js +++ b/screens/SignInScreen.js @@ -1,31 +1,117 @@ import React from "react"; -import { View } from "react-native"; +import { View, Button, StyleSheet, AsyncStorage } from "react-native"; import { Appbar, Text } from "react-native-paper"; +// import { PARSE_APP_ID, PARSE_SERVER_URL } from "react-native-dotenv"; +// console.log(PARSE_APP_ID); +// console.log(PARSE_SERVER_URL); + +// import Parse from "parse/react-native"; +// Parse.setAsyncStorage(AsyncStorage); +// Parse.initialize(PARSE_APP_ID); +// Parse.serverURL = PARSE_SERVER_URL; + +// var GameScore = Parse.Object.extend("GameScore"); +// var gameScore = new GameScore(); + +// gameScore.set("score", 1337); +// gameScore.set("playerName", "Sean Plott"); +// gameScore.set("cheatMode", false); + +// gameScore.save().then( +// gameScore => { +// // Execute any logic that should take place after the object is saved. +// alert("New object created with objectId: " + gameScore.id); +// }, +// error => { +// // Execute any logic that should take place if the save fails. +// // error is a Parse.Error with an error code and message. +// alert("Failed to create new object, with error code: " + error.message); +// } +// ); + + class SignInScreen extends React.Component { static navigationOptions = { - drawerLabel: "Settings" - // drawerIcon: ({ tintColor }) => ( - // - // ) + title: "Please sign in" + }; + + render() { + return ( + +