react-native-safari-view 0,0,0 codeclimate eslint travis-ci npm CocoaPods

A React Native wrapper for Safari View Controller.

React Native Safari View

npm version npm downloads Code Climate

React Native Safari View is a Safari View Controller wrapper for React Native.

react-native-safari-view

Documentation

Install

npm i --save react-native-safari-view

Usage

Linking the Library

In order to use Safari View, you must first link the library your project. There’s excellent documentation on how to do this in the React Native Docs.

Displaying the Safari View

Once you’ve linked the library, you’ll want to make it available to your app by requiring it:

var SafariView = require('react-native-safari-view');

Displaying the Safari View is as simple as calling:

SafariView.show({
  url: 'https://github.com/naoufal'
});

Example

Using Safari View in your app will usually look like this:

import React, { Component } from "react";
import SafariView from "react-native-safari-view";

class YourComponent extends Component {
  constructor(props) {
    super(props);
  }

  _pressHandler() {
    SafariView.isAvailable()
      .then(SafariView.show({
        url: "https://github.com/naoufal"
      }))
      .catch(error => {
        // Fallback WebView code for iOS 8 and earlier
      });
  }

  render() {
    return (
      <View>
        ...
        <Button onPress={this._pressHandler}>
          Show Safari View
        </Button>
      </View>
    );
  }
}

Methods

show(safariOptions)

Displays a Safari View with the provided url.

Arguments - safariOptions - An Object containing a url key and optionally a readerMode key, a tintColor, and/or a barTintColor.

safariOptions - url - A String containing the url you want to load in the Safari View - readerMode - A Boolean indicating to use Safari’s Reader Mode if available - tintColor - A String containing a hex, rgba or rgba color to use for the browser controls - barTintColor - A String containing a hex, rgba or rgba color to use for the background of the browser controls (only available on iOS 10 and higher)

Examples

SafariView.show({
  url: "http://facebook.github.io/react/blog/2015/03/26/introducing-react-native.html",
  readerMode: true // optional,
  tintColor: "#000" // optional
  barTintColor: "#fff" // optional
});

isAvailable()

Checks if Safari View is available on the device.

Example

SafariView.isAvailable()
  .then(available => {
    console.log("SafariView is available.");
  })
  .catch(error => {
    console.log(error);
  });

Events

The following events are fired by the Safari View.

onShow

Example

let showSubscription = SafariView.addEventListener(
  "onShow",
  () => {
    StatusBarIOS.setStyle("light-content");
  }
);

onDismiss

Example

let dismissSubscription = SafariView.addEventListener(
  "onDismiss",
  () => {
    StatusBarIOS.setStyle("default");
  }
);

License

Copyright © 2015, Naoufal Kadhom

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Related Repositories

react-native-safari-view

react-native-safari-view

A React Native wrapper for Safari View Controller. ...

react-native-sfsafariviewcontroller

react-native-sfsafariviewcontroller

An SFSafariViewController wrapper for React Native presenting Safari View in a modal ...


Top Contributors

naoufal jerolimov mnylen bgryszko rt2zz weinshel ptmt aforty dozoisch jamesreggio myusuf3 trabianmatt ojkelly plrthink

Dependencies

package version
dev eslint 2.0.0
eslint-plugin-react 3.0.0

Releases

-   v1.2.0 zip tar
-   v1.1.0 zip tar
-   v1.0.0 zip tar
-   v0.1.1 zip tar
-   v0.1.0 zip tar