Skip to content

Conversation

pjcabrera
Copy link
Contributor

We have a requirement in our app, to open in mobile Safari, any http:// and https:// links displayed in a web view. Our web view is not full screen, and displaying external content in that web view is outside of the scope of our app, so we open them in mobile Safari.

I've forked the WebView component and added a property, externalHTTPEnabled, and modified the RCTWebView implementation of

- (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

to check if the user has tapped a link and that the URL has a prefix of 'http' (this matches 'http://' and 'https://' URLs).

By adding a property and defaulting to false, this added functionality doesn't break existing behavior.

The functionality is enabled through a flag. The default value of the flag is false, preserving the existing functionality (not loading links in Safari).
@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @nicklockwood, @donyu and @vjeux to be potential reviewers.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 13, 2015
@javache
Copy link
Member

javache commented Oct 14, 2015

It doesn't really make sense to me to create a WebView component, only then to immediately redirect the user to Safari, as you can already use LinkingIOS for this.

Are you using the webview to load any other content before this? Perhaps it would be useful to have a generic shouldStartLoadWithRequest callback that you can handle from the JS side?

@javache javache self-assigned this Oct 14, 2015
@nicklockwood
Copy link
Contributor

Yeah, this seems like the wrong API for this.

I can imagine it would be useful to have a generic way to intercept webview requests and execute arbitrary JS code, similar to the injectedJavaScript property, but with the ability to block or redirect the url.

But a blanket redirect of all links to Safari seems too specific of a use case to be something we'd want to expose as a public property.

@pjcabrera
Copy link
Contributor Author

@javache in our app, the webview is not full screen, it covers just a portion of the screen with other RN components and content. The webview is used to load HTML content from the backend. This backend HTML content sometimes has links, which we want to open in an external browser, since their content is not directly related to the use of the app.

I was thinking of your and @nicklockwood's review comments. Perhaps it would seem more useful to you if I implemented a callback that allows devs to respond to shouldStartLoadWithRequest on the React Native side of their app?

[Edit: Oops, read your review comments too fast and just realized you were indeed proposing I implement a callback to JS.]

@pjcabrera pjcabrera closed this Oct 21, 2015
@pjcabrera pjcabrera deleted the added-configurable-flag-to-open-http-https-links-in-MobileSafari branch October 21, 2015 17:27
@pjcabrera
Copy link
Contributor Author

@nicklockwood @javache I've opened pull request #3643 with the suggested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants