-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WebView] Add props for overriding native component #15016
Conversation
@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 |
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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. |
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. |
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Oops, my bad! I'll remember that for next time. |
@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
I need this too |
@hramos Just checking in, and wondering if there's anything holding the merge back? |
* @platform ios | ||
*/ | ||
viewManager: PropTypes.object, | ||
}), | ||
* Used on Android only, controls whether the given list of URL prefixes should |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, noted. Seems to be caused by an earlier merge. Thanks! 👍
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 |
@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.js
andWebView.ios.js
userequireNativeComponent
, 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
nativeConfig
prop on WebView. I've also moved the extrarequireNativeComponent
config toWebView.extraNativeComponentConfig
for 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
nativeConfig
prop on theWebView
. You also send in theviewManager
since 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.