Another post on native applications will cover building a simple native mobile application using React Native.

What is React Native?

React Native is a JavaScript framework that allows you to write native mobile applications for iOS and Android. It is based on React , Facebook’s  JavaScript library for web applications.

In the example using React Native we will be creating the same application we created using Xamarin. A simple list showing customer records from the DataFlex WebApp Order Entry workspace.

To get started with React Native we need to install the NPM package manager (or your favorite package manager). You can find NPM over at https://www.npmjs.com/

For this example we will also utilize expo. Expo is an open source toolchain that makes building Android and iOS apps under React Native very easy.

to install expo enter the following command line to install using NPM

this will install the expo toolchain globally on your computer so it is available to initialize projects

the next step is to initialize your application. We will use expo to do that and this will create a folder for your application so in a command shell navigate to the folder you want to create your application in and enter the following.

The first line will create a folder called DataFlexAndReact and then initialize the project. Then we simply navigate to that folder and start the development server.

Now lets look at a simple HelloWorld React project

Running this will obviously show the text Hello world!.

Now we want to modify this program to show a list of customers and then fill the list with data from our web service

first we add some state information to our project. We do this by adding some property settings in the constructor

then we need to call the web service and get the list of customers.

We do this by hooking into componentDidMount

we use the fetch method to call the web service to return the json data. When the data is received we save the data in our state object.

now lets add some code to the render function to render a flatlist in our view

first we need to add some imports at the top as follows

then we modify the render function as follows

we show the text Customers as a header  and then create a FlatList using the data from our state information.

The renderItem function renders each list item by showing the customer name and address. To satisfy the flatlist we also need to add a unique identifier for each item which will be the customer number as a string.

Saving the changes will automatically build the updated application. Lets take a look at the application running on an Android phone

Michael Salzlechner is the CEO of StarZen Technologies, Inc.

He was part of the Windows Team at Data Access Worldwide that created the DataFlex for Windows Product before joining StarZen Technologies. StarZen Technologies provides consulting services as well as custom Application development and third party products specifically for DataFlex developers