npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@matt-block/react-native-in-app-browser

v3.2.2

Published

React Native in-app browser

Downloads

256

Readme

React Native In-App Browser

npm (scoped) license: mit

In-App browser support for React Native, using Chrome Custom Tabs on Android and Safari View Controller on iOS.

Compatibility

⚠️Support has ended on October 1st 2020.

It is recommended migrating to react-native-inappbrowser-reborn for continued support and more features.

| React Native | Library | Status | End-of-Life | | :---------------: | :---------------------------------------: | :--------: | :---------: | | 0.60.0 - 0.62.x | npm (scoped) | EOL | 2020-10-01 | | 0.57.x - 0.59.x | npm v2 (scoped) | EOL | 2020-01-03 | | 0.57.x - 0.59.5 | npm v1 (scoped) | EOL | 2019-06-09 |

Using Expo? Check out WebBrowser.

Installation

Install the package via Yarn or npm:

yarn add @matt-block/react-native-in-app-browser

# or
npm install --save @matt-block/react-native-in-app-browser

Linking

React Native 0.60.0 and later

Packages are autolinked, however an extra step for iOS projects is needed:

cd ios && pod install && cd ..

React Native 0.59.x and below

Manually link the native module to your project:

react-native link @matt-block/react-native-in-app-browser

Note for iOS projects

In order for Xcode projects to build when using Swift-based libraries, your main app project must contain Swift code and a bridging header. If your app project does not contain any Swift code, add a single empty .swift file and an empty bridging header to your app.

If your Xcode project already makes use of Swift code you can safely ignore this note.

Usage

⚠️ Still using an older version ? Check out the migration guides.

import { InAppBrowser } from "@matt-block/react-native-in-app-browser";


// Minimal setup.
InAppBrowser.open("https://www.wikipedia.org/").catch(error => {
  console.log(error);
});


// With platform-specific optional settings.
InAppBrowser.open("https://www.wikipedia.org/", {
  android: {
    //...,
  },
  ios: {
    //...,
  },
}).catch(error => {
  console.log(error);
});


// Using async/await.
async onClickHandler() {
  try {
    await InAppBrowser.open("https://www.wikipedia.org/");
  } catch (error) {
    console.log(error);
  }
}

Startup optimizations (Android only)

Chrome Custom Tabs exposes methods to reduce the start time of a custom tab activity.

For information on how these work, check Custom Tabs - Example and Usage Optimization

import { InAppBrowser } from "@matt-block/react-native-in-app-browser";

InAppBrowser.warmup();
InAppBrowser.mayLaunchUrl("https://wikipedia.org");

Programmatically close (iOS only)

It is possible to manually dismiss the iOS in-app instance by calling the method close.

import { InAppBrowser } from "@matt-block/react-native-in-app-browser";

InAppBrowser.close();

This is not possible on Android since Chrome Custom Tabs do not expose such functionality and Activity workarounds would bring this package way out of scope.

Settings

The main method open accepts an object with settings objects for each platform:

import { InAppBrowser } from "@matt-block/react-native-in-app-browser";

InAppBrowser.open("https://www.wikipedia.org/", {
  android: {},
  ios: {}
});

Settings can also be initialized separately with configure so that each open call won't need to specify them each time:

import { InAppBrowser } from "@matt-block/react-native-in-app-browser";

// Somewhere in your app initialization logic.
InAppBrowser.configure({
  android: {},
  ios: {}
});

// Other part of your code base.
// Previously initialized settings will apply.
InAppBrowser.open("https://www.wikipedia.org/");

Note that open will still accept settings as always but will effectively perform a merge between the initialized properties and the provided settings object (which will have priority over the initialized properties):

import { InAppBrowser } from "@matt-block/react-native-in-app-browser";

// Somewhere in your app initialization logic.
InAppBrowser.configure({
  android: {
    toolbarColor: "red",
    showTitle: true
  }
});

// Other part of your code base.
// Merged settings for this call will result in:
//
// - toolbarColor: "blue",
// - showTitle: true
InAppBrowser.open("https://www.wikipedia.org/", {
  android: {
    toolbarColor: "blue"
  }
});

The properties for each platform settings are described below.

Android

Each setting is optional. Furthermore, settings with invalid values will be ignored and their default values will be used.

| Setting | Type | Default | Description | | --------------------- | --------------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------- | | toolbarColor | string | undefined | The color to tint the background of the toolbar.Provided color can be in any @ctrl/tinycolor supported format. | | showTitle | boolean | false | Flag to toggle if the page title should be shown in the custom tab. | | closeButtonIcon | string (as resolved by importing an image file) | undefined | Custom close button icon.Provided icon must be a .png, .jpg, or .gif file. | | addDefaultShareMenu | boolean | false | Flag to toggle the default share menu. |

iOS

Each setting is optional. Furthermore, settings with invalid values will be ignored and their default values will be used. Also, settings that are not supported by the iOS version at runtime will be ignored as well.

| Setting | Type | Default | Description | | --------------------------- | --------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | preferredBarTintColor | string | undefined | The color to tint the background of the navigation bar and the toolbar.Provided color can be in any @ctrl/tinycolor supported format.Available on: iOS >= 10.0. | | preferredControlTintColor | string | undefined | The color to tint the control buttons on the navigation bar and the toolbar.Provided color can be in any @ctrl/tinycolor supported format.Available on: iOS >= 10.0. | | barCollapsingEnabled | boolean | true | Available on: iOS >= 11.0. | | dismissButtonStyle | string | undefined | Available on: iOS >= 11.0. | | entersReaderIfAvailable | boolean | false | A value that specifies whether Safari should enter Reader mode, if it is available.Available on: iOS >= 11.0. |

Example

An example project showcasing the various configurations can be found in the example directory. Simply clone this repository, navigate into example, install the dependencies and run the app.

git clone https://github.com/matei-radu/react-native-in-app-browser.git
cd react-native-in-app-browser/example
yarn install
yarn start
yarn android # or yarn ios

License

Copyright (c) 2018-2020 Matei Bogdan Radu.

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.