Description: This is a React-Native "Flashcard" app. A list of user-defined flashcard decks is displayed, and the user can quiz themselves and create new quizzes as desired. It utilizes AsyncStorage for persistance.
Environment: This app was tested (and runs) on iOS 12 devices.
Installation/Launching:
To install, you should have a node.js server available on your system. Clone or download the app at https://github.com/pnellesen/reactnd-native-flashcards to a directory of your choosing (unzip if downloading) then run "npm install" or "yarn install" in the app directory. Once all the required node modules have been installed, run "npm start" or "yarn start" to run the application. Note that you will need the "Expo" app running on the device you intend to use.
(There was a note during the class that there could be issues uing NPM instead of yarn for react-native, but I didn't notice anything unusual when testing it. I did, however, use "yarn" during most of my development)
Basic operations:
Startup: Upon loading, the user will see a list of Flashcard "Decks", showing the name of the Deck and the number of questions (or "Cards") in the deck. At the bottom of screen there are 2 tabs - "Quiz List" and "New Quiz". The currently selected tab will be colored purple.
View Quiz (or Card) - when a quiz is pressed, the quiz selected will display an "expand" animation, then the user will be taken to a screen displaying the Quiz name, the number of questions in the Quiz, and the option to either add a new question to the quiz, or to start the Quiz. Note that if the quiz currently has no questions in it, the "Start Quiz" button will be disabled.
Question/Answer View - this view displays the following information:
1. Quiz/Deck Title
2. Which question the user is on, and the number of questions remaining in the quiz
3. The question
4. A "Show answer" button which will display the answer when pressed (along with changing to "Hide Answer" to hide the answer if desired)
5. "Correct" and "Incorrect" buttons which will be tracked to display the score when the quiz is finished
6. When either "Correct" or "Incorrect" button is selected, the user will either be taken to the next question, or will be shown the "Quiz Finished" view if all questions have been answered.
Quiz Finished View - diplays the following information:
1. Quiz/Deck Title
2. Text informing the user they have completed the quiz, and showing the number they answered correctly out of the total number in the quiz.
3. "Restart Quiz" and "Return to Deck" buttons which will allow the user to restart the quiz, or return to the View Quiz screen, respectively.
Add new Question/Answer card - displays the following.
1. Quiz/Deck Title
2. Text field for the new question
3. Text field for the new answer
4. Submit button - disabled until both question and answer have text in them. When pressed, will append a the new question/answer card to current Quiz and will return the user to the View Quiz screen.
New Quiz View This screen allows the user to add a new quiz to the deck. It consists of a text field to enter the name of the quiz, and a submit button which will append a new quiz to the deck. When pressed, the user will be taken to the View Quiz screen for the new deck, where they can proceed to add new answer/question cards for that quiz.
Notifications:
A notification is set for 8:00am to remind the user (if notification permission has been granted to the Expo app) to finish at least one quiz that day. A reminder is also displayed on the "Deck List View" screen until the user completes one quiz, at which point it will be reset to be displayed the next day.
Additional technical notes
Redux was not used in this project. There is one "app-wide" parameter and function utilized by all components, which is easily handled via ScreenProps in the MainNavigation (StackNavigator) Component
Data is persisted in device AsyncStorage using a simple object of the following form:
data = {
'quiz key': {// unique random character/number string
id: 'same as quiz key',
title: 'Title text',
questions: [// array of objects of the following from
{
question: 'question text?',
answer: 'answer text',
correct: null,
showAnswer: false
},
],
lastCompletedDate:null// flag used to determine if any quizzes have been completed for the current day
},
...
}
Acknowledgements:
Idea for the "Expanding button" animation used when user selects a deck is based on discussion found at https://code.tutsplus.com/tutorials/practical-animations-in-react-native--cms-27567
=========================================================================
This project was bootstrapped with Create React Native App.
Below you'll find information about performing common tasks. The most recent version of this guide is available here.
- Updating to New Releases
- Available Scripts
- Writing and Running Tests
- Environment Variables
- Customizing App Display Name and Icon
- Sharing and Deployment
- Troubleshooting
You should only need to update the global installation of create-react-native-app
very rarely, ideally never.
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.
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 for up-to-date information about package version compatibility.
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.
Runs your app in development mode.
Open it in the Expo app 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.
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:
npm start --reset-cache
# or
yarn start --reset-cache
Runs the jest test runner on your tests.
Like npm start
, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed.
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 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:
- Make sure that you can run adb from your terminal.
- Open Genymotion and navigate to
Settings -> ADB
. Select “Use custom Android SDK tools” and update with your Android SDK directory.
- Find Genymotion’s copy of adb. On macOS for example, this is normally
/Applications/Genymotion.app/Contents/MacOS/tools/
. - Add the Genymotion tools directory to your path (instructions for Mac, Linux, and Windows).
- Make sure that you can run adb from your terminal.
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.
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 set up.
You can edit app.json
to include configuration keys under the expo
key.
To change your app's display name, set the expo.name
key in app.json
to an appropriate string.
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.
This project is set up to use 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 for an example test. The jest documentation is also a wonderful resource, as is the React Native testing tutorial.
You can configure some of Create React Native App's behavior using environment variables.
When starting your project, you'll see something like this for your project URL:
exp://192.168.0.2:19000
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.
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:
Mac and Linux:
REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start
Windows:
set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname'
npm start
The above example would cause the development server to listen on exp://my-custom-ip-address-or-hostname:19000
.
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.
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.
Install the exp
command-line tool, and run the publish command:
$ npm i -g exp
$ exp publish
You can also use a service like Expo's standalone builds if you want to get an IPA/APK for distribution without having to build the native code yourself.
If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio.
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.
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 for more details about this option.
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.
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:
exp://192.168.0.1:19000
Try opening Safari or Chrome on your phone and loading
http://192.168.0.1:19000
and
http://192.168.0.1:19001
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 with details about these steps and any other error messages you may have received.
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. If you are using a VPN you may need to disable it.
If you're on a Mac, there are a few errors that users sometimes see when attempting to npm run ios
:
- "non-zero exit code: 107"
- "You may need to install Xcode" but it is already installed
- and others
There are a few steps you may want to take to troubleshoot these kinds of errors:
- 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.
- 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-runnpm/yarn run ios
after doing so. - 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-runnpm/yarn run ios
.
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 for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses.
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.