├── .babelrc ├── .flowconfig ├── .gitignore ├── .watchmanconfig ├── App.js ├── App.test.js ├── README.md ├── app.json ├── app ├── components │ ├── Button │ │ ├── LoginButton.js │ │ ├── LogoutButton.js │ │ ├── RegistrationButton.js │ │ ├── index.js │ │ └── styles.js │ ├── Container │ │ ├── Container.js │ │ ├── index.js │ │ └── styles.js │ ├── Forms │ │ ├── LoginForm.js │ │ ├── RegistrationForm.js │ │ ├── index.js │ │ └── styles.js │ └── Logo │ │ ├── Logo.js │ │ ├── images │ │ └── logo.png │ │ ├── index.js │ │ └── styles.js ├── config │ └── routes.js ├── index.js └── screens │ ├── Home.js │ ├── Login.js │ ├── Main.js │ └── Registration.js ├── package-lock.json ├── package.json └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["babel-preset-expo"], 3 | "env": { 4 | "development": { 5 | "plugins": ["transform-react-jsx-source"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore templates for 'react-native init' 6 | /node_modules/react-native/local-cli/templates/.* 7 | 8 | ; Ignore RN jest 9 | /node_modules/react-native/jest/.* 10 | 11 | ; Ignore RNTester 12 | /node_modules/react-native/RNTester/.* 13 | 14 | ; Ignore the website subdir 15 | /node_modules/react-native/website/.* 16 | 17 | ; Ignore the Dangerfile 18 | /node_modules/react-native/danger/dangerfile.js 19 | 20 | ; Ignore Fbemitter 21 | /node_modules/fbemitter/.* 22 | 23 | ; Ignore "BUCK" generated dirs 24 | /node_modules/react-native/\.buckd/ 25 | 26 | ; Ignore unexpected extra "@providesModule" 27 | .*/node_modules/.*/node_modules/fbjs/.* 28 | 29 | ; Ignore polyfills 30 | /node_modules/react-native/Libraries/polyfills/.* 31 | 32 | ; Ignore various node_modules 33 | /node_modules/react-native-gesture-handler/.* 34 | /node_modules/expo/.* 35 | /node_modules/react-navigation/.* 36 | /node_modules/xdl/.* 37 | /node_modules/reqwest/.* 38 | /node_modules/metro-bundler/.* 39 | 40 | [include] 41 | 42 | [libs] 43 | node_modules/react-native/Libraries/react-native/react-native-interface.js 44 | node_modules/react-native/flow/ 45 | node_modules/expo/flow/ 46 | 47 | [options] 48 | emoji=true 49 | 50 | module.system=haste 51 | 52 | module.file_ext=.js 53 | module.file_ext=.jsx 54 | module.file_ext=.json 55 | module.file_ext=.ios.js 56 | 57 | munge_underscores=true 58 | 59 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 60 | 61 | suppress_type=$FlowIssue 62 | suppress_type=$FlowFixMe 63 | suppress_type=$FlowFixMeProps 64 | suppress_type=$FlowFixMeState 65 | suppress_type=$FixMe 66 | 67 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\) 68 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)?:? #[0-9]+ 69 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 70 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 71 | 72 | unsafe.enable_getters_and_setters=true 73 | 74 | [version] 75 | ^0.56.0 76 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # expo 4 | .expo/ 5 | 6 | # dependencies 7 | /node_modules 8 | 9 | # misc 10 | .env.local 11 | .env.development.local 12 | .env.test.local 13 | .env.production.local 14 | 15 | npm-debug.log* 16 | yarn-debug.log* 17 | yarn-error.log* 18 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /App.js: -------------------------------------------------------------------------------- 1 | import App from './app/index'; 2 | 3 | export default App; -------------------------------------------------------------------------------- /App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import App from './App'; 3 | 4 | import renderer from 'react-test-renderer'; 5 | 6 | it('renders without crashing', () => { 7 | const rendered = renderer.create().toJSON(); 8 | expect(rendered).toBeTruthy(); 9 | }); 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app). 2 | 3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md). 4 | 5 | ## Table of Contents 6 | 7 | * [Updating to New Releases](#updating-to-new-releases) 8 | * [Available Scripts](#available-scripts) 9 | * [npm start](#npm-start) 10 | * [npm test](#npm-test) 11 | * [npm run ios](#npm-run-ios) 12 | * [npm run android](#npm-run-android) 13 | * [npm run eject](#npm-run-eject) 14 | * [Writing and Running Tests](#writing-and-running-tests) 15 | * [Environment Variables](#environment-variables) 16 | * [Configuring Packager IP Address](#configuring-packager-ip-address) 17 | * [Adding Flow](#adding-flow) 18 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon) 19 | * [Sharing and Deployment](#sharing-and-deployment) 20 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community) 21 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app) 22 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app) 23 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio) 24 | * [Should I Use ExpoKit?](#should-i-use-expokit) 25 | * [Troubleshooting](#troubleshooting) 26 | * [Networking](#networking) 27 | * [iOS Simulator won't open](#ios-simulator-wont-open) 28 | * [QR Code does not scan](#qr-code-does-not-scan) 29 | 30 | ## Updating to New Releases 31 | 32 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never. 33 | 34 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies. 35 | 36 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility. 37 | 38 | ## Available Scripts 39 | 40 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing. 41 | 42 | ### `npm start` 43 | 44 | Runs your app in development mode. 45 | 46 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal. 47 | 48 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script: 49 | 50 | ``` 51 | npm start -- --reset-cache 52 | # or 53 | yarn start -- --reset-cache 54 | ``` 55 | 56 | #### `npm test` 57 | 58 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests. 59 | 60 | #### `npm run ios` 61 | 62 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed. 63 | 64 | #### `npm run android` 65 | 66 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App: 67 | 68 | ##### Using Android Studio's `adb` 69 | 70 | 1. Make sure that you can run adb from your terminal. 71 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location). 72 | 73 | ##### Using Genymotion's `adb` 74 | 75 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`. 76 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)). 77 | 3. Make sure that you can run adb from your terminal. 78 | 79 | #### `npm run eject` 80 | 81 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project. 82 | 83 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up. 84 | 85 | ## Customizing App Display Name and Icon 86 | 87 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key. 88 | 89 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string. 90 | 91 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency. 92 | 93 | ## Writing and Running Tests 94 | 95 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/en/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/en/tutorial-react-native.html). 96 | 97 | ## Environment Variables 98 | 99 | You can configure some of Create React Native App's behavior using environment variables. 100 | 101 | ### Configuring Packager IP Address 102 | 103 | When starting your project, you'll see something like this for your project URL: 104 | 105 | ``` 106 | exp://192.168.0.2:19000 107 | ``` 108 | 109 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides. 110 | 111 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable: 112 | 113 | Mac and Linux: 114 | 115 | ``` 116 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start 117 | ``` 118 | 119 | Windows: 120 | ``` 121 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' 122 | npm start 123 | ``` 124 | 125 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`. 126 | 127 | ## Adding Flow 128 | 129 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept. 130 | 131 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native. 132 | 133 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps: 134 | 135 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig) 136 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number. 137 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`. 138 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`). 139 | 140 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. 141 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience. 142 | 143 | To learn more about Flow, check out [its documentation](https://flow.org/). 144 | 145 | ## Sharing and Deployment 146 | 147 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service. 148 | 149 | ### Publishing to Expo's React Native Community 150 | 151 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account. 152 | 153 | Install the `exp` command-line tool, and run the publish command: 154 | 155 | ``` 156 | $ npm i -g exp 157 | $ exp publish 158 | ``` 159 | 160 | ### Building an Expo "standalone" app 161 | 162 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself. 163 | 164 | ### Ejecting from Create React Native App 165 | 166 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio. 167 | 168 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html). 169 | 170 | #### Should I Use ExpoKit? 171 | 172 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option. 173 | 174 | ## Troubleshooting 175 | 176 | ### Networking 177 | 178 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports. 179 | 180 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see: 181 | 182 | ``` 183 | exp://192.168.0.1:19000 184 | ``` 185 | 186 | Try opening Safari or Chrome on your phone and loading 187 | 188 | ``` 189 | http://192.168.0.1:19000 190 | ``` 191 | 192 | and 193 | 194 | ``` 195 | http://192.168.0.1:19001 196 | ``` 197 | 198 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received. 199 | 200 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. 201 | 202 | ### iOS Simulator won't open 203 | 204 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`: 205 | 206 | * "non-zero exit code: 107" 207 | * "You may need to install Xcode" but it is already installed 208 | * and others 209 | 210 | There are a few steps you may want to take to troubleshoot these kinds of errors: 211 | 212 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store. 213 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so. 214 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`. 215 | 216 | ### QR Code does not scan 217 | 218 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses. 219 | 220 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually. 221 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "sdkVersion": "23.0.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /app/components/Button/LoginButton.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { TouchableOpacity, Text, View } from 'react-native'; 3 | import PropTypes from 'prop-types'; 4 | 5 | import styles from './styles'; 6 | 7 | const LoginButton = ({ onPress }) => ( 8 | 12 | Login 13 | 14 | ); 15 | 16 | LoginButton.propTypes = { 17 | onPress: PropTypes.func, 18 | }; 19 | 20 | export default LoginButton; -------------------------------------------------------------------------------- /app/components/Button/LogoutButton.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { TouchableOpacity, Text, View } from 'react-native'; 3 | import PropTypes from 'prop-types'; 4 | 5 | import styles from './styles'; 6 | 7 | const LogoutButton = ({ onPress }) => ( 8 | 12 | Logout 13 | 14 | ); 15 | 16 | LogoutButton.propTypes = { 17 | onPress: PropTypes.func, 18 | }; 19 | 20 | export default LogoutButton; -------------------------------------------------------------------------------- /app/components/Button/RegistrationButton.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { TouchableOpacity, Text, View } from 'react-native'; 3 | 4 | import styles from './styles'; 5 | 6 | const RegistrationButton = ({ onPress }) => ( 7 | 11 | Registration 12 | 13 | ); 14 | 15 | export default RegistrationButton; -------------------------------------------------------------------------------- /app/components/Button/index.js: -------------------------------------------------------------------------------- 1 | import LoginButton from './LoginButton'; 2 | import RegistrationButton from './RegistrationButton'; 3 | import LogoutButton from './LogoutButton'; 4 | import styles from './styles'; 5 | 6 | export { LoginButton, RegistrationButton, LogoutButton, styles }; -------------------------------------------------------------------------------- /app/components/Button/styles.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StyleSheet } from 'react-native'; 3 | 4 | const styles = StyleSheet.create({ 5 | toolbarButton: { 6 | marginLeft:1, 7 | marginRight:1, 8 | backgroundColor: 'rgba(255,255,255,0.2)', 9 | minWidth: 100, 10 | minHeight: 40, 11 | alignItems: 'center', 12 | justifyContent: 'center', 13 | borderRadius: 5 14 | }, 15 | }); 16 | 17 | export default styles; -------------------------------------------------------------------------------- /app/components/Container/Container.js: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types'; 2 | import React from 'react'; 3 | import { View } from 'react-native'; 4 | 5 | import styles from './styles'; 6 | 7 | const Container = ({ children }) => ( 8 | 9 | {children} 10 | 11 | ); 12 | 13 | Container.propTypes = { 14 | children: PropTypes.any, 15 | }; 16 | 17 | export default Container; -------------------------------------------------------------------------------- /app/components/Container/index.js: -------------------------------------------------------------------------------- 1 | import Container from './Container'; 2 | import styles from './styles'; 3 | 4 | export { Container, styles }; -------------------------------------------------------------------------------- /app/components/Container/styles.js: -------------------------------------------------------------------------------- 1 | import EStyleSheet from 'react-native-extended-stylesheet'; 2 | 3 | export default EStyleSheet.create({ 4 | container: { 5 | flex: 1, 6 | alignItems: 'center', 7 | justifyContent: 'center', 8 | backgroundColor: '$primaryBlue', 9 | }, 10 | }); -------------------------------------------------------------------------------- /app/components/Forms/LoginForm.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | View, 4 | Text, 5 | TextInput, 6 | TouchableOpacity, 7 | StyleSheet, 8 | AsyncStorage 9 | } from 'react-native'; 10 | import { StackNavigator } from 'react-navigation'; 11 | 12 | import PropTypes from 'prop-types'; 13 | 14 | import styles from './styles'; 15 | 16 | const ACCESS_TOKEN = 'access_token'; 17 | 18 | 19 | class LoginForm extends React.Component { 20 | constructor(props){ 21 | super(props); 22 | 23 | this.state ={ 24 | username: "", 25 | password: "", 26 | error: "" 27 | } 28 | } 29 | 30 | ComponentDidMount(){ 31 | this._loadInitialState().done(); 32 | } 33 | 34 | _loadInitialState = async () => { 35 | let token = await AsyncStorage.getItem(ACCESS_TOKEN); 36 | if (token !== null) { 37 | this.props.navigation.navigate('Main'); 38 | } 39 | } 40 | 41 | async storeToken(accessToken) { 42 | try { 43 | await AsyncStorage.setItem(ACCESS_TOKEN, accessToken); 44 | this.getToken(); 45 | } catch(error) { 46 | console.log("Something went wrong") 47 | } 48 | } 49 | 50 | async getToken() { 51 | try { 52 | let token = await AsyncStorage.getItem(ACCESS_TOKEN); 53 | console.log("token is:" + token); 54 | } catch(error) { 55 | console.log("Something went wrong") 56 | } 57 | } 58 | 59 | async onLoginButtonPress() { 60 | try { 61 | let response = await fetch('http://evwwa.com/corporate_track/index.php', { 62 | method: 'POST', 63 | headers: { 64 | "optcode": "login", 65 | 'Accept': 'application/json', 66 | 'Content-Type': 'application/json', 67 | }, 68 | body: JSON.stringify({ 69 | username: this.state.username, 70 | password: this.state.password 71 | }) 72 | }); 73 | let res = await response.json(); 74 | if (response.status >= 200 && response.status < 300) { 75 | this.setState({error: ""}); 76 | let accessToken = res.accesstoken; 77 | this.storeToken(accessToken); 78 | console.log("Response success is: " + accessToken); 79 | this.props.navigation.navigate('Main'); 80 | } else { 81 | let error = res; 82 | throw error; 83 | } 84 | } catch(error){ 85 | console.log("catch error: " + error); 86 | let formError = JSON.parse(error); 87 | let errorArray = []; 88 | for(let key in formError) { 89 | if(formError[key].length > 1){ 90 | formError[key].map(error => errorArray.push(`${key} ${error}`)) 91 | } else { 92 | errorArray.push(`${key} ${formError[key]}`) 93 | } 94 | } 95 | this.setState({error: errorArray}); 96 | } 97 | } 98 | 99 | render() { 100 | return ( 101 | 102 | this.setState({username: val})} 104 | keyboardType='email-address' 105 | placeholder='Email or Mobile Num' 106 | placeholderTextColor='rgba(225,225,225,0.7)' 107 | underlineColorAndroid='transparent'/> 108 | 109 | this.setState({password: val})} 111 | placeholder='Password' 112 | placeholderTextColor='rgba(225,225,225,0.7)' 113 | underlineColorAndroid='transparent' 114 | secureTextEntry/> 115 | 116 | 118 | LOGIN 119 | 120 | 121 | 122 | ); 123 | } 124 | } 125 | 126 | export default LoginForm; 127 | -------------------------------------------------------------------------------- /app/components/Forms/RegistrationForm.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, Text, TextInput, TouchableOpacity, StyleSheet} from 'react-native'; 3 | import PropTypes from 'prop-types'; 4 | 5 | import styles from './styles'; 6 | 7 | class RegistrationForm extends React.Component { 8 | constructor(){ 9 | super(); 10 | this.state = { 11 | fullname: "", 12 | username: "", 13 | password: "", 14 | errors: [], 15 | } 16 | } 17 | 18 | async onRegistrationButtonPress() { 19 | try { 20 | let response = await fetch('http://evwwa.com/corporate_track/index.php', { 21 | method: 'POST', 22 | headers: { 23 | "optcode": "register", 24 | 'Accept': 'application/json', 25 | 'Content-Type': "application/json", 26 | }, 27 | body: JSON.stringify({ 28 | fullname: this.state.fullname, 29 | username: this.state.username, 30 | password: this.state.password 31 | }) 32 | }); 33 | let res = await response.text(); 34 | 35 | if(response.status >= 200 && response.status < 300) { 36 | console.log("response success is: " + res); 37 | } else { 38 | let errors = res; 39 | throw errors; 40 | } 41 | 42 | } catch(errors) { 43 | console.log("catch errors: " + errors); 44 | let formErrors = JSON.parse(errors); 45 | let errorsArray = []; 46 | for(let key in formErrors) { 47 | if(formErrors[key].length > 1){ 48 | formErrors[key].map(error => errorsArray.push(`${key} ${error}`)) 49 | } else { 50 | errorsArray.push(`${key} ${formErrors[key]}`) 51 | } 52 | } 53 | this.setState({errors: errorsArray}); 54 | } 55 | } 56 | 57 | render(){ 58 | return( 59 | 60 | this.setState({fullname: val})} 62 | placeholder='Name' 63 | placeholderTextColor='rgba(225,225,225,0.7)' 64 | underlineColorAndroid='transparent'/> 65 | 66 | this.setState({username: val})} 68 | autoCapitalize="none" 69 | onSubmitEditing={() => this.passwordInput.focus()} 70 | autoCorrect={false} 71 | keyboardType='email-address' 72 | returnKeyType="next" 73 | placeholder='Email Address' 74 | placeholderTextColor='rgba(225,225,225,0.7)' 75 | underlineColorAndroid='transparent'/> 76 | 77 | this.setState({password: val})} 79 | returnKeyType="go" 80 | ref={(input)=> this.passwordInput = input} 81 | placeholder='Password' 82 | placeholderTextColor='rgba(225,225,225,0.7)' 83 | underlineColorAndroid='transparent' 84 | secureTextEntry/> 85 | 86 | Registration 87 | 88 | 89 | ); 90 | } 91 | } 92 | 93 | const Errors = (props) => { 94 | return ( 95 | 96 | {props.errors.map((error, i) => {error})} 97 | 98 | ) 99 | } 100 | 101 | export default RegistrationForm; 102 | -------------------------------------------------------------------------------- /app/components/Forms/index.js: -------------------------------------------------------------------------------- 1 | import LoginForm from './LoginForm'; 2 | import RegistrationForm from './RegistrationForm'; 3 | import styles from './styles'; 4 | 5 | export { LoginForm, RegistrationForm, styles }; -------------------------------------------------------------------------------- /app/components/Forms/styles.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StyleSheet } from 'react-native'; 3 | 4 | const styles = StyleSheet.create({ 5 | container: { 6 | flex: 1, 7 | padding: 20, 8 | alignSelf: 'stretch', 9 | backgroundColor: '#4F6D7A', 10 | }, 11 | input:{ 12 | height: 40, 13 | backgroundColor: 'rgba(225,225,225,0.2)', 14 | marginBottom: 10, 15 | padding: 10, 16 | color: '#fff' 17 | }, 18 | buttonContainer:{ 19 | backgroundColor: '#2980b6', 20 | paddingVertical: 15 21 | }, 22 | buttonText:{ 23 | color: '#fff', 24 | textAlign: 'center', 25 | fontWeight: '700' 26 | }, 27 | error: { 28 | color: 'red', 29 | paddingTop: 10 30 | } 31 | }); 32 | 33 | export default styles; -------------------------------------------------------------------------------- /app/components/Logo/Logo.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, Image, Text } from 'react-native'; 3 | import styles from './styles'; 4 | 5 | const Logo = () => ( 6 | 7 | 8 | 9 | ); 10 | 11 | export default Logo; -------------------------------------------------------------------------------- /app/components/Logo/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashraf777/React-Native-Authentication-with-React-Navigation/2e4d26dd1eb17b04dfe2522996255b7230e17653/app/components/Logo/images/logo.png -------------------------------------------------------------------------------- /app/components/Logo/index.js: -------------------------------------------------------------------------------- 1 | import Logo from './Logo'; 2 | import styles from './styles'; 3 | 4 | export { Logo, styles }; -------------------------------------------------------------------------------- /app/components/Logo/styles.js: -------------------------------------------------------------------------------- 1 | import { Dimensions } from 'react-native'; 2 | import EStyleSheet from 'react-native-extended-stylesheet'; 3 | 4 | const imageWidth = Dimensions.get('window').width /2; 5 | 6 | export default EStyleSheet.create({ 7 | container: { 8 | alignItems: 'center', 9 | }, 10 | containerImage: { 11 | alignItems: 'center', 12 | justifyContent: 'center', 13 | width: imageWidth, 14 | height: imageWidth, 15 | }, 16 | }); -------------------------------------------------------------------------------- /app/config/routes.js: -------------------------------------------------------------------------------- 1 | import { StatusBar } from 'react-native'; 2 | import { StackNavigator, NavigationActions } from 'react-navigation'; 3 | 4 | import Home from '../screens/Home'; 5 | import Login from '../screens/Login'; 6 | import Registration from '../screens/Registration'; 7 | import Main from '../screens/Main'; 8 | 9 | import { StyleSheet } from 'react-native'; 10 | 11 | const styles = StyleSheet.create({ 12 | header: { 13 | backgroundColor: 'transparent', 14 | position: 'absolute', 15 | height: 50, 16 | top: 0, 17 | left: 0, 18 | right: 0, 19 | }, 20 | }); 21 | 22 | const Navigator = StackNavigator( 23 | { 24 | Home: { 25 | screen: Home, 26 | navigationOptions: { 27 | headerStyle: styles.header, 28 | } 29 | }, 30 | Login: { 31 | screen: Login, 32 | navigationOptions: { 33 | headerStyle: styles.header, 34 | } 35 | }, 36 | Registration: { 37 | screen: Registration, 38 | navigationOptions: { 39 | headerStyle: styles.header, 40 | } 41 | }, 42 | Main: { 43 | screen: Main, 44 | navigationOptions: { 45 | headerStyle: styles.header, 46 | headerLeft: null, 47 | } 48 | }, 49 | }, 50 | { 51 | headerMode: 'screen', 52 | }); 53 | 54 | export default Navigator; -------------------------------------------------------------------------------- /app/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import EStyleSheet from 'react-native-extended-stylesheet'; 3 | import {StatusBar, View} from 'react-native'; 4 | 5 | import Navigator from './config/routes'; 6 | 7 | EStyleSheet.build({ 8 | $primaryBlue: '#4F6D7A', 9 | }); 10 | 11 | export default class Home extends React.Component { 12 | render() { 13 | return ( 14 | 15 | 16 | 17 | ) 18 | } 19 | } -------------------------------------------------------------------------------- /app/screens/Home.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StatusBar, StyleSheet, View, AsyncStorage, Text } from 'react-native'; 3 | 4 | import { Container } from '../components/Container'; 5 | import { Logo } from '../components/Logo'; 6 | import { LoginButton, RegistrationButton, LogoutButton } from '../components/Button'; 7 | 8 | const ACCESS_TOKEN = 'access_token'; 9 | 10 | class Home extends React.Component { 11 | 12 | constructor(props){ 13 | super(props); 14 | 15 | this.state ={ 16 | accessToken: "", 17 | } 18 | } 19 | 20 | async componentDidMount() { 21 | const token = await AsyncStorage.getItem(ACCESS_TOKEN); 22 | if (token) { 23 | this.setState({ accessToken: token }); 24 | console.log(token); 25 | this.props.navigation.navigate('Main'); 26 | } else { 27 | this.setState({ accessToken: false }); 28 | } 29 | } 30 | 31 | handleLoginButtonPress = () => { 32 | this.props.navigation.navigate('Login'); 33 | }; 34 | handleRegistrationButtonPress = () => { 35 | this.props.navigation.navigate('Registration'); 36 | }; 37 | handleLogoutButtonPress = () => { 38 | try { 39 | AsyncStorage.removeItem(ACCESS_TOKEN); 40 | } catch(error) { 41 | console.log("Something went wrong") 42 | } 43 | } 44 | 45 | render() { 46 | if (!this.state.accessToken) { 47 | return ( 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | ); 57 | } else { 58 | return ( 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | ) 67 | } 68 | } 69 | } 70 | 71 | const styles = StyleSheet.create({ 72 | buttonContainer: { 73 | flexDirection:'row', 74 | justifyContent: 'center', 75 | paddingHorizontal: 10 76 | }, 77 | }); 78 | 79 | export default Home; 80 | -------------------------------------------------------------------------------- /app/screens/Login.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | View, 4 | Text, 5 | TextInput, 6 | TouchableOpacity, 7 | KeyboardAvoidingView, 8 | StatusBar, 9 | StyleSheet, 10 | AsyncStorage 11 | } from 'react-native'; 12 | 13 | import { StackNavigator, NavigationActions } from 'react-navigation'; 14 | 15 | import PropTypes from 'prop-types'; 16 | 17 | import styles from '../components/Forms/styles'; 18 | 19 | import { Container } from '../components/Container'; 20 | import { Logo } from '../components/Logo'; 21 | 22 | const ACCESS_TOKEN = 'access_token'; 23 | 24 | const resetAction = NavigationActions.reset({ 25 | index: 0, 26 | actions: [ 27 | NavigationActions.navigate({ routeName: 'Main'}) 28 | ] 29 | }) 30 | 31 | class Login extends React.Component { 32 | constructor(props){ 33 | super(props); 34 | 35 | this.state ={ 36 | username: "", 37 | password: "", 38 | error: "" 39 | } 40 | } 41 | 42 | componentDidMount(){ 43 | this._loadInitialState().done(); 44 | } 45 | 46 | _loadInitialState = async () => { 47 | let token = await AsyncStorage.getItem(ACCESS_TOKEN); 48 | if (token !== null) { 49 | this.props.navigation.navigate('Main'); 50 | } 51 | } 52 | 53 | 54 | async storeToken(accessToken) { 55 | try { 56 | await AsyncStorage.setItem(ACCESS_TOKEN, accessToken); 57 | this.getToken(); 58 | } catch(error) { 59 | console.log("Something went wrong") 60 | } 61 | } 62 | 63 | async getToken() { 64 | try { 65 | let token = await AsyncStorage.getItem(ACCESS_TOKEN); 66 | console.log("token is:" + token); 67 | } catch(error) { 68 | console.log("Something went wrong") 69 | } 70 | } 71 | 72 | async onLoginButtonPress() { 73 | try { 74 | let response = await fetch('http://evwwa.com/corporate_track/index.php', { 75 | method: 'POST', 76 | headers: { 77 | "optcode": "login", 78 | 'Accept': 'application/json', 79 | 'Content-Type': 'application/json', 80 | }, 81 | body: JSON.stringify({ 82 | username: this.state.username, 83 | password: this.state.password 84 | }) 85 | }); 86 | let res = await response.json(); 87 | if (response.status >= 200 && response.status < 300) { 88 | this.setState({error: ""}); 89 | let accessToken = res.accesstoken; 90 | this.storeToken(accessToken); 91 | console.log("Response success is: " + accessToken); 92 | if(!accessToken) { 93 | this.props.navigation.navigate('Home'); 94 | } else { 95 | this.props.navigation.dispatch(resetAction); 96 | } 97 | } else { 98 | let error = res; 99 | throw error; 100 | } 101 | } catch(error){ 102 | console.log("catch error: " + error); 103 | let formError = JSON.parse(error); 104 | let errorArray = []; 105 | for(let key in formError) { 106 | if(formError[key].length > 1){ 107 | formError[key].map(error => errorArray.push(`${key} ${error}`)) 108 | } else { 109 | errorArray.push(`${key} ${formError[key]}`) 110 | } 111 | } 112 | this.setState({error: errorArray}); 113 | } 114 | } 115 | 116 | render() { 117 | return ( 118 | 119 | 120 | 121 | 122 | this.setState({username: val})} 124 | keyboardType='email-address' 125 | placeholder='Email or Mobile Num' 126 | placeholderTextColor='rgba(225,225,225,0.7)' 127 | underlineColorAndroid='transparent'/> 128 | 129 | this.setState({password: val})} 131 | placeholder='Password' 132 | placeholderTextColor='rgba(225,225,225,0.7)' 133 | underlineColorAndroid='transparent' 134 | secureTextEntry/> 135 | 136 | 138 | LOGIN 139 | 140 | 141 | 142 | ); 143 | } 144 | } 145 | 146 | export default Login; -------------------------------------------------------------------------------- /app/screens/Main.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StatusBar, View, Text, StyleSheet, AsyncStorage } from 'react-native'; 3 | 4 | import { Container } from '../components/Container'; 5 | 6 | import { Logo } from '../components/Logo'; 7 | import { LogoutButton } from '../components/Button'; 8 | 9 | const ACCESS_TOKEN = 'access_token'; 10 | 11 | class Main extends React.Component { 12 | 13 | handleLogoutButtonPress = () => { 14 | try { 15 | AsyncStorage.removeItem(ACCESS_TOKEN); 16 | this.props.navigation.navigate('Home'); 17 | console.log("Logged Out") 18 | } catch(error) { 19 | console.log("Something went wrong") 20 | } 21 | } 22 | 23 | render() { 24 | return ( 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | ); 33 | } 34 | } 35 | 36 | const styles = StyleSheet.create({ 37 | buttonContainer: { 38 | flexDirection:'row', 39 | justifyContent: 'center', 40 | paddingHorizontal: 10 41 | }, 42 | }); 43 | 44 | export default Main; -------------------------------------------------------------------------------- /app/screens/Registration.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | StatusBar, 4 | View, 5 | Text, 6 | StyleSheet, 7 | KeyboardAvoidingView, 8 | ScrollView, 9 | TextInput, 10 | TouchableOpacity, 11 | AsyncStorage 12 | } from 'react-native'; 13 | 14 | import { NavigationActions } from 'react-navigation'; 15 | 16 | import { Logo } from '../components/Logo'; 17 | 18 | import { styles } from '../components/Forms'; 19 | 20 | const ACCESS_TOKEN = 'access_token'; 21 | 22 | const resetAction = NavigationActions.reset({ 23 | index: 0, 24 | actions: [ 25 | NavigationActions.navigate({ routeName: 'Main'}) 26 | ] 27 | }) 28 | 29 | class Registration extends React.Component { 30 | constructor(props){ 31 | super(props); 32 | this.state = { 33 | fullname: "", 34 | username: "", 35 | password: "", 36 | errors: [], 37 | } 38 | } 39 | 40 | componentDidMount(){ 41 | this._loadingInitialState().done(); 42 | } 43 | 44 | _loadingInitialState = async () => { 45 | let token = await AsyncStorage.getItem(ACCESS_TOKEN); 46 | if (token !== null) { 47 | this.props.navigation.navigate('Main'); 48 | } 49 | } 50 | 51 | async storeToken(accessToken) { 52 | try { 53 | await AsyncStorage.setItem(ACCESS_TOKEN, accessToken); 54 | this.getToken(); 55 | } catch(error) { 56 | console.log("Something went wrong") 57 | } 58 | } 59 | 60 | async getToken() { 61 | try { 62 | let token = await AsyncStorage.getItem(ACCESS_TOKEN); 63 | console.log("token is:" + token); 64 | } catch(error) { 65 | console.log("Something went wrong") 66 | } 67 | } 68 | 69 | async onRegistrationButtonPress() { 70 | try { 71 | let response = await fetch('http://evwwa.com/corporate_track/index.php', { 72 | method: 'POST', 73 | headers: { 74 | "optcode": "register", 75 | 'Accept': 'application/json', 76 | 'Content-Type': "application/json", 77 | }, 78 | body: JSON.stringify({ 79 | fullname: this.state.fullname, 80 | username: this.state.username, 81 | password: this.state.password 82 | }) 83 | }); 84 | 85 | let res = await response.json(); 86 | if (response.status >= 200 && response.status < 300) { 87 | this.setState({error: ""}); 88 | let accessToken = res.accesstoken; 89 | this.storeToken(accessToken); 90 | console.log("Response success is: " + accessToken); 91 | if(!accessToken) { 92 | this.props.navigation.navigate('Home'); 93 | } else { 94 | this.props.navigation.dispatch(resetAction); 95 | } 96 | 97 | } else { 98 | let error = res; 99 | throw error; 100 | } 101 | 102 | } catch(errors) { 103 | console.log("catch errors: " + errors); 104 | let formErrors = JSON.parse(errors); 105 | let errorsArray = []; 106 | for(let key in formErrors) { 107 | if(formErrors[key].length > 1){ 108 | formErrors[key].map(error => errorsArray.push(`${key} ${error}`)) 109 | } else { 110 | errorsArray.push(`${key} ${formErrors[key]}`) 111 | } 112 | } 113 | this.setState({errors: errorsArray}); 114 | } 115 | } 116 | 117 | render() { 118 | return ( 119 | 120 | 121 | 122 | 123 | 124 | this.setState({fullname: val})} 126 | placeholder='Name' 127 | placeholderTextColor='rgba(225,225,225,0.7)' 128 | underlineColorAndroid='transparent'/> 129 | 130 | this.setState({username: val})} 132 | autoCapitalize="none" 133 | onSubmitEditing={() => this.passwordInput.focus()} 134 | autoCorrect={false} 135 | keyboardType='email-address' 136 | returnKeyType="next" 137 | placeholder='Email Address' 138 | placeholderTextColor='rgba(225,225,225,0.7)' 139 | underlineColorAndroid='transparent'/> 140 | 141 | this.setState({password: val})} 143 | returnKeyType="go" 144 | ref={(input)=> this.passwordInput = input} 145 | placeholder='Password' 146 | placeholderTextColor='rgba(225,225,225,0.7)' 147 | underlineColorAndroid='transparent' 148 | secureTextEntry/> 149 | 150 | Registration 151 | 152 | 153 | 154 | 155 | ); 156 | } 157 | } 158 | 159 | const Errors = (props) => { 160 | return ( 161 | 162 | {props.errors.map((error, i) => {error})} 163 | 164 | ) 165 | } 166 | 167 | export default Registration; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ExApp", 3 | "version": "0.1.0", 4 | "private": true, 5 | "devDependencies": { 6 | "jest-expo": "23.0.0", 7 | "react-native-scripts": "1.8.1", 8 | "react-test-renderer": "16.0.0" 9 | }, 10 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", 11 | "scripts": { 12 | "start": "react-native-scripts start", 13 | "eject": "react-native-scripts eject", 14 | "android": "react-native-scripts android", 15 | "ios": "react-native-scripts ios", 16 | "test": "node node_modules/jest/bin/jest.js --watch" 17 | }, 18 | "jest": { 19 | "preset": "jest-expo" 20 | }, 21 | "dependencies": { 22 | "color": "^2.0.0", 23 | "expo": "^23.0.4", 24 | "moment": "^2.18.1", 25 | "react": "16.0.0", 26 | "react-native": "0.50.3", 27 | "react-native-extended-stylesheet": "^0.8.0", 28 | "react-navigation": "1.0.0-beta.22" 29 | } 30 | } 31 | --------------------------------------------------------------------------------