docs/en/framework/ui/react-native/index.md
//[doc-seo]
{
"Description": "Learn how to set up your development environment for React Native with ABP Framework, enabling seamless mobile app integration!"
}
//[doc-params]
{
"Architecture": ["Monolith", "Tiered", "Microservice"]
}
The React Native mobile option is available for Team or higher licenses
The ABP platform provides a basic React Native startup template to develop mobile applications integrated with your ABP-based backends.
React Native gif
Please follow the steps below to prepare your development environment for React Native.
Note: The Web View method (recommended for quick testing) doesn't require an emulator or simulator. If you prefer a CLI-based approach for Android, you can check the setting up android emulator without android studio guide as an alternative.
You have multiple options to initiate a new React Native project that works with ABP:
ABP Studio is the most convenient and flexible way to create a React Native application based on the ABP framework. Follow the tool documentation and select the option below:
React Native option
The ABP CLI is another way to create an ABP solution with a React Native application. Install the ABP CLI and run the following command in your terminal:
abp new MyCompanyName.MyProjectName -csf -u <angular or mvc> -m react-native
For more options, visit the CLI manual.
This command creates a solution containing an Angular or MVC project (depending on your choice), a .NET Core project, and a React Native project.
Recommended: For faster development and testing, we recommend using the Web View option first, as it requires fewer backend modifications. The backend configuration described in the next section is only needed if you want to test on Android emulators or iOS simulators.
Before running the React Native application, install the dependencies by running yarn install or npm install in the react-native directory.
The quickest way to test the application is by using the web view. While testing on a physical device is also supported, we recommend using local HTTPS development as it requires fewer backend modifications.
Follow these steps to set up the web view:
react-native directory and start the application by running: yarn web
mkcert localhost
yarn create:local-proxy
The default port is 443. To use a different port, specify the SOURCE_PORT environment variable:
4. If you changed the port in the previous step, update the apiUrl in Environment.ts accordingly.
5. Update the mobile application settings in the database and re-run the migrations. If you specified a custom port, ensure the port is updated in the configuration as well:
"OpenIddict": {
"Applications": {
"MyApplication_Mobile": {
"ClientId": "MyApplication_Mobile",
"RootUrl": "https://localhost"
}
}
}
If you prefer to test on an Android emulator or iOS simulator, you'll need to configure the backend as described in the section below. Follow these steps:
react-native folder and run yarn install or npm install if you have not already.Environment.ts file in the react-native folder and replace the localhost address in the apiUrl and issuer properties with your local IP address as shown below:{{ if Architecture == "Monolith" }}
react native monolith environment local IP
{{ else if Architecture == "Tiered" }}
react native tiered environment local IP
Make sure that
issuermatches the running address of the.AuthServerproject,apiUrlmatches the running address of the.HttpApi.Hostor.Webproject.
{{ else }}
react native microservice environment local IP
Make sure that
issuermatches the running address of the.AuthServerproject,apiUrlmatches the running address of the.AuthServerproject.
{{ end }}
yarn start or npm start. Wait for the Expo CLI to print the options.The React Native application was generated with Expo. Expo is a set of tools built around React Native to help you quickly start an app, and it includes many features.
expo-cli-options
In the image above, you can start the application on an Android emulator, an iOS simulator, or a physical phone by scanning the QR code with the Expo Client or by choosing the corresponding option.
React Native login screen on iPhone 16
yarn start or npm start command.React Native login screen on Android Device
Enter admin as the username and 1q2w3E as the password to log in to the application.
The application is up and running. You can continue to develop your application based on this startup template.
React Native application does not trust the auto-generated .NET HTTPS certificate. You should use HTTP during the development.
To disable the HTTPS-only settings of OpenIddict, open the {{ if Architecture == "Monolith" }}MyProjectNameHttpApiHostModule{{ else if Architecture == "Tiered" }}MyProjectNameAuthServerModule{{ end }} project and add the following code block to the PreConfigureServices method:
#if DEBUG
PreConfigure<OpenIddictServerBuilder>(options =>
{
options.UseAspNetCore()
.DisableTransportSecurityRequirement();
});
#endif
Important: Before running the backend application, make sure you have completed the database migration if you are starting with a fresh database. The backend application requires the database to be properly initialized.
A React Native application running on an Android emulator or a physical phone cannot connect to the backend on localhost. To resolve this, you need to run the backend application using the Kestrel configuration.
{{ if Architecture == "Monolith" }}
React Native monolith host project configuration
appsettings.json file in the .DbMigrator folder. Replace the localhost address in the RootUrl property with your local IP address. Then, run the database migrator.appsettings.Development.json file in the .HttpApi.Host folder. Add this configuration to accept global requests for testing the React Native application in the development environment.
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:44323" //replace with your host port
}
}
}
}
{{ else if Architecture == "Tiered" }}
React Native tiered project configuration
appsettings.json file in the .DbMigrator folder. Replace the localhost address in the RootUrl property with your local IP address. Then, run the database migrator.appsettings.Development.json file in the .AuthServer folder. Add this configuration to accept global requests for testing the React Native application in the development environment.
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:44337"
}
}
}
}
appsettings.Development.json file in the .HttpApi.Host folder. Add this configuration to accept global requests. Additionally, you need to configure the authentication server as mentioned above.
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:44389" //replace with your host port
}
}
},
"AuthServer": {
"Authority": "http://192.168.1.37:44337/", //replace with your IP and authentication port
"MetaAddress": "http://192.168.1.37:44337/",
"RequireHttpsMetadata": false,
"Audience": "MyTieredProject" //replace with your application name
}
}
{{ else if Architecture == "Microservice" }}
React Native microservice project configuration
appsettings.Development.json file in the .AuthServer folder. Add this configuration to accept global requests for testing the React Native application in the development environment.
{
"App": {
"EnablePII": true
},
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:44319"
}
}
}
}
appsettings.Development.json file in the .AdministrationService folder. Add this configuration to accept global requests for testing the React Native application in the development environment. You should also provide the authentication server configuration. Additionally, you need to apply the same process for all services you will use in the React Native application.
{
"App": {
"EnablePII": true
},
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:44357"
}
}
},
"AuthServer": {
"Authority": "http://192.168.1.36:44319/",
"MetaAddress": "http://192.168.1.36:44319/",
"RequireHttpsMetadata": false,
"Audience": "AdministrationService"
}
}
appsettings.json file in the .IdentityService folder. Replace the localhost configuration with your local IP address for the React Native application.
{
//...
"OpenIddict": {
"Applications": {
//...
"ReactNative": {
"RootUrl": "exp://192.168.1.36:19000"
},
"MobileGateway": {
"RootUrl": "http://192.168.1.36:44347/"
}
//...
}
//...
}
}
//gateways/mobile/MyMicroserviceProject.MobileGateway/Properties/launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://192.168.1.36:44347" //update with your IP address
}
},
"profiles": {
//...
"MyMicroserviceProject.MobileGateway": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "http://192.168.1.36:44347",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
//gateways/mobile/MyMicroserviceProject.MobileGateway/appsettings.json
{
//Update clusters with your IP address
//...
"ReverseProxy": {
//...
"Clusters": {
"AuthServer": {
"Destinations": {
"AuthServer": {
"Address": "http://192.168.1.36:44319/"
}
}
},
"Administration": {
"Destinations": {
"Administration": {
"Address": "http://192.168.1.36:44357/"
}
}
},
"Saas": {
"Destinations": {
"Saas": {
"Address": "http://192.168.1.36:44330/"
}
}
},
"Identity": {
"Destinations": {
"Identity": {
"Address": "http://192.168.1.36:44397/"
}
}
},
"Language": {
"Destinations": {
"Identity": {
"Address": "http://192.168.1.36:44310/"
}
}
}
}
}
}
Run the backend application(s) as described in the getting started document.