1.1.0 • Published 3 years ago

react-native-trusted-web-activity v1.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

NPM Downloads NPM Version

react-native-trusted-web-activity

This module can be used to implement Android's Trusted Web Activity in a React Native project. This is only available for Android.

Getting started

$ npm install react-native-trusted-web-activity --save

Mostly automatic installation

$ react-native link react-native-trusted-web-activity

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactlibrary.RNTrustedWebActivityPackage; to the imports at the top of the file
  • Add new RNTrustedWebActivityPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-trusted-web-activity'
    project(':react-native-trusted-web-activity').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-trusted-web-activity/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-trusted-web-activity')

Setup

  1. In your android/app/src/main/AndroidManifest.xml file add the following inside the <application> tag,

    <activity android:name="android.support.customtabs.trusted.LauncherActivity">
        <meta-data
            android:name="android.support.customtabs.trusted.DEFAULT_URL"
            android:value="${defaultUrl}"/>
    
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
    
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
    
            <data
                android:host="${hostName}"
                android:scheme="https"/>
        </intent-filter>
    </activity>
  2. In your android/app/build.gradle,

    defaultConfig {
    	...
    	manifestPlaceholders = [
                hostName       : "www.example.com",		//replace with the url of your PWA
                defaultUrl     : "https://www.example.com",		//replace with the url of your PWA
                assetStatements: '[{ "relation": ["delegate_permission/common.handle_all_urls"], ' +
                        '"target": {"namespace": "web", "site": "https://www.example.com"}}]'
        ] 	//replace with the url of your PWA
    
        buildConfigField "String", "DEFAULT_URL", "\"${manifestPlaceholders.defaultUrl}\""
        multiDexEnabled true
    	...
    }

    and,

    dependencies{
    	...
    	implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.0.1'
    	...
    }

Usage

import RNTrustedWebActivity from 'react-native-trusted-web-activity';

//Replace the url with your PWA's URL
RNTrustedWebActivity.goToPWA('https://www.example.com');
1.1.0

3 years ago

1.0.10

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago