react-native-chrome-custom-tabs
v0.0.2
Published
Launch Chrome Custom Tabs from your React Native app
Downloads
30
Maintainers
Readme
react-native-chrome-custom-tabs
Installation
npm install --save react-native-chrome-custom-tabs
- Add the following to
android/settings.gradle
:
include ':ReactNativeChromeCustomTabs', ':app'
project(':ReactNativeChromeCustomTabs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-chrome-custom-tabs/android')
- Add
compile project(':ReactNativeChromeCustomTabs')
todependencies
inandroid/app/build.gradle
- Import and register the module in your
MainActivity.java
file:
import com.dstaley.ReactNativeChromeCustomTabs.ChromeCustomTabsPackage; // <-- Import
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
private ReactInstanceManager mReactInstanceManager;
private ReactRootView mReactRootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new ChromeCustomTabsPackage(this)) // <-- Register
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "DemoReactNativeCustomTabs", null);
setContentView(mReactRootView);
}
Usage
var ChromeCustomTabsClient = require('react-native-chrome-custom-tabs');
// Tell Chrome to preload a URL
ChromeCustomTabsClient.mayLaunchUrl('http://i.imgur.com/6ogeF96.gif');
// Launch a Custom Tab
ChromeCustomTabsClient.launchCustomTab('http://i.imgur.com/xjdem.gif');
License
MIT