Allow source to be a required module#172
Conversation
|
Thanks for the PR. |
|
It broke normal It is not allowed to assign anything to this.props. On what react version did you test it? I have React 16.4.2. It was |
| }); | ||
| let source = this.props.source || {}; | ||
| if (typeof source == 'object') { | ||
| source.sendCookies = this.props.sendCookies; |
There was a problem hiding this comment.
source is still referencing to this.props.source
There was a problem hiding this comment.
Could be fixed by setting source like this I guess:
let source = { ...this.props.source };There was a problem hiding this comment.
Won't it break scenario with source={require('...')}?
There was a problem hiding this comment.
Indeed.
That's probably the if condition that fails, so how about a check like this instead:
if (typeof source == 'object' && source.constructor == Object) { //...There was a problem hiding this comment.
require() returns number in react-native world. I think the fix might be like
let source = this.props.source;
if (this.props.source && typeof this.props.source === 'object') {
source = Object.assign({}, this.props.source, {
sendCookies: this.props.sendCookies,
customUserAgent: this.props.customUserAgent || this.props.userAgent
});
if (this.props.html) {
source.html = this.props.html;
} else if (this.props.url) {
source.uri = this.props.url;
}
}
React-native's webview allow html files to be directly required.
The fix is pretty straighforward,
PropTypesalready allow a number as source, managed by React-native internal packager. The only difference come from the initialisation of thesourcevariable.For obvious reasons,
sendCookiesanduserAgentare being ignored.Fixes #54