Uh oh!
There was an error while loading. Please reload this page.
[WebView] Add props for overriding native component - #15016
Conversation
cbrevik
commented
Aug 4, 2017
@shergin did you have a chance to look at this one yet? |
@facebook-github-bot label Documentation @facebook-github-bot large-pr Attention: @facebook/react-native Generated by 🚫 dangerJS |
facebook-github-bot
commented
Aug 24, 2017
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
hramos
commented
Aug 30, 2017
It was failing to import due to the "cc:" line in the description, which gets re-parsed by arcanist during import. Edited and trying again. |
facebook-github-bot
commented
Aug 30, 2017
I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification. |
facebook-github-bot
commented
Aug 31, 2017
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
cbrevik
commented
Aug 31, 2017
Oops, my bad! I'll remember that for next time. |
facebook-github-bot
commented
Aug 31, 2017
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Lxxyx
commented
Sep 11, 2017
I need this too |
cbrevik
commented
Sep 13, 2017
@hramos Just checking in, and wondering if there's anything holding the merge back? |
| */ | ||
| viewManager: PropTypes.object, | ||
| }), | ||
| * Used on Android only, controls whether the given list of URL prefixes should |
There was a problem hiding this comment.
Here's why the PR hasn't landed - missing opening comment. I'll see if I can fix it on our side, no need to update your PR.
There was a problem hiding this comment.
Alright, noted. Seems to be caused by an earlier merge. Thanks! 👍
dahjelle
commented
Nov 16, 2017
Does this PR provide a mechanism for customizing |
@dahjelle What this PR enables is that you can extend So yes, you can override (Ideally maybe I should have created a |
dahjelle
commented
Nov 16, 2017
@cbrevik Thanks much! |
Opening a new PR for #10946 (see discussion there).
This PR builds upon #14775 (iOS ViewManager inheritance) and #14261 (more extensible Android WebView).
Motivation
When
WebView.android.jsandWebView.ios.jsuserequireNativeComponent, they are hard-coded to requireRCTWebView. This means if you want to re-use the same JS-logic, but require a custom native WebView-implementation, you have to duplicate the entire JS-code files.The same is true if you want to pass through any custom events or props, which you want to set on the custom native
WebView.What I'm trying to solve with this PR is to able to extend native WebView logic, and being able to re-use and extend existing WebView JS-logic.
This is done by adding a new
nativeConfigprop on WebView. I've also moved the extrarequireNativeComponentconfig toWebView.extraNativeComponentConfigfor easier re-use.Test plan
@jacobp100 has been kind enough to help me with docs for this new feature. So that is part of the PR and can be read for some information.
I've also created an example app which demonstrates how to use this functionality: https://github.com/cbrevik/webview-native-config-example
If you've implemented the native side as in the example repo above, it should be fairly easy to use from JavaScript like this:
As you see, you require the custom native implementation at the bottom, and send in that along with any custom props with the
nativeConfigprop on theWebView. You also send in theviewManagersince iOS requires that forstartLoadWithResult.Discussion
As noted in the original PR, this could in principle be done with more React Native components, to make it easier for the community to re-use and extend native components.