{"id":4634,"url":"https://github.com/naoufal/react-native-safari-view","last_synced_at":"2025-05-15T23:07:44.951Z","repository":{"id":43999789,"uuid":"38019068","full_name":"naoufal/react-native-safari-view","owner":"naoufal","description":"A React Native wrapper for Safari View Controller.","archived":false,"fork":false,"pushed_at":"2021-09-21T05:01:39.000Z","size":495,"stargazers_count":494,"open_issues_count":34,"forks_count":109,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-09T16:12:09.680Z","etag":null,"topics":["apple","react-native","safari","safari-view-controller"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-native-safari-view","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naoufal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-25T00:45:18.000Z","updated_at":"2025-01-13T09:23:06.000Z","dependencies_parsed_at":"2022-09-04T08:11:40.612Z","dependency_job_id":null,"html_url":"https://github.com/naoufal/react-native-safari-view","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naoufal%2Freact-native-safari-view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naoufal%2Freact-native-safari-view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naoufal%2Freact-native-safari-view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naoufal%2Freact-native-safari-view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naoufal","download_url":"https://codeload.github.com/naoufal/react-native-safari-view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254436949,"owners_count":22070947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple","react-native","safari","safari-view-controller"],"created_at":"2024-01-05T20:17:18.564Z","updated_at":"2025-05-15T23:07:38.460Z","avatar_url":"https://github.com/naoufal.png","language":"Objective-C","funding_links":[],"categories":["Components","组件","Libraries","Objective-C"],"sub_categories":["Web","Web相关","Communications"],"readme":"# React Native Safari View\n\n[![react-native version](https://img.shields.io/badge/react--native-0.40-blue.svg?style=flat-square)](http://facebook.github.io/react-native/releases/0.40)\n[![npm version](https://img.shields.io/npm/v/react-native-safari-view.svg?style=flat-square)](https://www.npmjs.com/package/react-native-safari-view)\n[![npm downloads](https://img.shields.io/npm/dm/react-native-safari-view.svg?style=flat-square)](https://www.npmjs.com/package/react-native-safari-view)\n[![Code Climate](https://img.shields.io/codeclimate/github/naoufal/react-native-safari-view.svg?style=flat-square)](https://codeclimate.com/github/naoufal/react-native-safari-view)\n\nReact Native Safari View is a [Safari View Controller](https://developer.apple.com/videos/wwdc/2015/?id=504) wrapper for [React Native](https://facebook.github.io/react-native/).\n\n![react-native-safari-view](https://cloud.githubusercontent.com/assets/1627824/8345135/ed5f7fc4-1ab8-11e5-814a-a3e9df0ede06.gif)\n\n## Documentation\n- [Install](https://github.com/naoufal/react-native-safari-view#install)\n- [Usage](https://github.com/naoufal/react-native-safari-view#usage)\n- [Example](https://github.com/naoufal/react-native-safari-view#example)\n- [Methods](https://github.com/naoufal/react-native-safari-view#methods)\n- [Events](https://github.com/naoufal/react-native-safari-view#events)\n- [License](https://github.com/naoufal/react-native-safari-view#license)\n\n## Install\n```shell\nnpm i --save react-native-safari-view\n```\n\n## Support\nDue to the rapid changes being made in the React Native ecosystem, we are not officially going to support this module on anything but the latest version of React Native. The current supported version is indicated on the React Native badge at the top of this README.  If it's out of date, we encourage you to submit a pull request!\n\n## Usage\n### Linking the Library\nIn 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](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content).\n\n### Displaying the Safari View\nOnce you've linked the library, you'll want to make it available to your app by requiring it:\n\n```js\nvar SafariView = require('react-native-safari-view');\n```\n\nDisplaying the Safari View is as simple as calling:\n```js\nSafariView.show({\n  url: 'https://github.com/naoufal'\n});\n```\n\n### URL Change Notifications\nThere isn't an API for retrieving URL changes provided by SFSafariViewController or its delegate in iOS, so there's no way to know where the user is navigating to. However, it is possible to get a notification when the Safari View navigates to an URL scheme specified by your app (e.g. `your-app-name://`). This is especially useful for implementing callback oriented flows such as in OAuth2 / OpenID Connect. \n\nTo get URL notifications for your URL scheme you'll need to:\n 1. Register an [URL scheme](https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html#//apple_ref/doc/uid/TP40007072-CH6-SW10) in your Xcode Project\n 2. Make sure you've set up [Linking](https://facebook.github.io/react-native/docs/linking.html) in your react-native project.\n 3. Listen for URL changes in your react-native code (i.e. `Linking.addEventListener('url', eventHandler)`);\n \n\n## Example\nUsing Safari View in your app will usually look like this:\n```js\nimport React, { Component } from \"react\";\nimport SafariView from \"react-native-safari-view\";\n\nclass YourComponent extends Component {\n  constructor(props) {\n    super(props);\n  }\n\n  _pressHandler() {\n    SafariView.isAvailable()\n      .then(SafariView.show({\n        url: \"https://github.com/naoufal\"\n      }))\n      .catch(error =\u003e {\n        // Fallback WebView code for iOS 8 and earlier\n      });\n  }\n\n  render() {\n    return (\n      \u003cView\u003e\n        ...\n        \u003cButton onPress={this._pressHandler}\u003e\n          Show Safari View\n        \u003c/Button\u003e\n      \u003c/View\u003e\n    );\n  }\n}\n```\n\n## Methods\n\n### show(safariOptions)\nDisplays a Safari View with the provided url.\n\n__Arguments__\n- `safariOptions` - An `Object` containing a `url` key and optionally a `readerMode` key, a `tintColor`, and/or a `barTintColor`.\n\n__safariOptions__\n- `url` - A `String` containing the url you want to load in the Safari View\n- `readerMode` - A `Boolean` indicating to use Safari's Reader Mode if available\n- `tintColor` - A `String` containing a hex, rgba or rgba color to use for the browser controls\n- `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)\n- `fromBottom` - A 'Boolean' indicating to open the Safari View from the bottom\n\n__Examples__\n```js\nSafariView.show({\n  url: \"http://facebook.github.io/react/blog/2015/03/26/introducing-react-native.html\",\n  readerMode: true // optional,\n  tintColor: \"#000\" // optional\n  barTintColor: \"#fff\" // optional\n});\n```\n\n### isAvailable()\nChecks if Safari View is available on the device.\n\n__Example__\n```js\nSafariView.isAvailable()\n  .then(available =\u003e {\n    console.log(\"SafariView is available.\");\n  })\n  .catch(error =\u003e {\n    console.log(error);\n  });\n```\n\n### dismiss()\nDismisses the currently active Safari View.\n\n__Example__\n```js\nSafariView.dismiss()\n```\n\n## Events\nThe following events are fired by the Safari View.\n\n### onShow\n__Example__\n```js\nlet showSubscription = SafariView.addEventListener(\n  \"onShow\",\n  () =\u003e {\n    StatusBar.setBarStyle(\"light-content\");\n  }\n);\n```\n\n### onDismiss\n__Example__\n```js\nlet dismissSubscription = SafariView.addEventListener(\n  \"onDismiss\",\n  () =\u003e {\n    StatusBar.setBarStyle(\"default\");\n  }\n);\n```\n\n## License\nCopyright (c) 2015, [Naoufal Kadhom](http://naoufal.com)\n\nPermission 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.\n\nTHE 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.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaoufal%2Freact-native-safari-view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaoufal%2Freact-native-safari-view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaoufal%2Freact-native-safari-view/lists"}