Tap-And-Go Project Setup With React Native and NFC Manager

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the The newline Guide to NFCs with React Native course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to The newline Guide to NFCs with React Native, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course The newline Guide to NFCs with React Native

Hello, in this lesson we will set up our tab and go project skeleton, including install and set up the navigation library, react navigation, install and set up the UI component library, react native vector icons and react native paper. Write our home screen UI and make our first screen navigation. If you are already familiar with the above libraries, feel free to skip this lesson. However, if your native experience is mostly a wrong expo, I suggest you watch this video and follow along. First, you will need to create a new Re-native project, using Re-native COI and do all the NFC specific configuration as well as library installation. Just like we mentioned in the previous Tech Counter-GAN app. After all this, you should see the Re-native NFC Manager library is installed and your skeleton project should run properly as well. Next, install our library for navigation. The library we will use is react navigation. The installation and configuration process is well documented in re-navigation. org. Duck getting started. You should be able to follow along smoothly. And since we are using Re-native COI, we should follow the corresponding sections in the document. As you can see, react navigation is a complex library. So, it also depends on lots of other libraries. Here I list all the dependencies. Let's install all of them right now. Since most of the dependencies list here contain native code, we need to perform a part install. Now we would like to use Re-navigation in our project. Create a srcapp.js file. Then go back to re-navigation.org website. Go to the next page and copy the Hello World example. Come back to our app and paste all the code into it. Then go to index.js and point the app component from app.js to srcapp.js. Oops, there is an error. What happened? Maybe it's because we just installed those new libraries and our Re-native package fails to hot reload all of them. Let's restart the package and try it again. It still fails, but the error is changed. It says "require native component, our end screen, are not found in ui-manager ". This issue is because we haven't reload our native code yet. Even though the JavaScript part has been updated, it still needs the corresponding native code to work properly. Let's rerun the app using Xcode. Remember, after you install any libraries with native code or assets, you need to restart the package and rerun the app with your platform IDE to make sure the native code is reloaded. Now it works. Next, we'd like to install Re-native paper as our primary UI library. And this library depends on another library. Re-native vector icons, which provides lots of awesome icons. The Re-native vector icons library also contains native code and assets. So we need to perform part install as well. There are two extra steps for Re-native vector icons. For iOS, we will need to add info.plist and add a key called "fans provided by application". This value is an array. Add an element with the value "materialcommunityicons.ttf" into this array. This font file is required by Re-native paper. The final result should look like this. For Andre, we will need to add one line into our "endry app build.gradle" file. The idea here is to include library specific build files in our project. The final result should look like this. Of course, we should restart Re-native package and rerun our app using "scode" as well. Now we can use Re-native paper in our project. Let's go to Re-native papers getting started page. It seems that the only required step is to wrap our whole app in provider from Re-native paper. Let's do it now. Let's do a quick refactor. We would like to extract the navigation related code into a single file called "appnavigator". Then go back to our app.js. Import and use the "appnavigator" component just created. Next, we would like to extract the home screen out of our app navigator. First, create a "src screens" directory. So we can put all screen components here. Then create a "homescreen.js" file inside this directory. Copy the original "homescreen" code from "appnavigator" into "homescreen.js". Go back to "appnavigator" and get rid of the old content. Okay, now we have separated our screen component from our navigator component. Let's quickly build our user interface for a home screen. This screen should have two primary buttons, one called "tap", which let users read and death from NFC tags and another called "link", which let the users write and death into NFC tags. As you can see, the button component comes from Re-native paper and it looks pretty good. Let's look at the styling. It also pretty straightforward. Now, it's time for our first navigation. The term "navigation" means to jump from one screen to another screen. Let's first create a new screen called "tap detail screen". Copy all the content from "homescreen". Get rid of most of it, leaving only "tap detail". The next step is to register our "tap detail screen" into our "appnavigator". This process is quite simple. First, import the component and add a stack.screen. Give it a name and point the component prop to "tap detail screen". Now our new screen is registered. So we should be able to navigate from "homescreen" to "tap detail screen". Go to "homescreen" and destructor the "navigation prop". Then add an "unpress handler" to our "tap" button. Inside it, simply call "navigation.navigate" and pass the screen name into it. As you can see, we can now jump forward and backward between the "home" and " tap detail" screens, thanks to "reinavigation". Thank you. [BLANK_AUDIO]