Skip to content

Commit 262d286

Browse files
RSNarakelset
authored andcommitted
Warn when 'scalesPageToFit' prop is used
Summary: @public The `WKWebView` class doesn't expose a `scalesPageToFit` property, unlike `UIWebView`. Therefore, the `scalesPageToFit` RN prop is be a bit tricky to implement with `WKWebView`. For the time being, this diff adds warnings to `<WebView/>` whenever `useWebKit={true}` and `scalesPageToFit` is set. I've also updated the documentation to reflect that we don't support `scalesPageToFit` prop with the new implementation of `<WebView/>`. Reviewed By: shergin Differential Revision: D6429271 fbshipit-source-id: adf858cb67ba221c70d6d6f1bd6cff505e90c365
1 parent f46dbc2 commit 262d286

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Libraries/Components/WebView/WebView.ios.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ class WebView extends React.Component {
324324
* Boolean that controls whether the web content is scaled to fit
325325
* the view and enables the user to change the scale. The default value
326326
* is `true`.
327+
*
328+
* On iOS, when `useWebKit=true`, this prop will not work.
327329
*/
328330
scalesPageToFit: PropTypes.bool,
329331

@@ -403,7 +405,6 @@ class WebView extends React.Component {
403405

404406
static defaultProps = {
405407
originWhitelist: WebViewShared.defaultOriginWhitelist,
406-
scalesPageToFit: true,
407408
};
408409

409410
state = {
@@ -416,11 +417,28 @@ class WebView extends React.Component {
416417
if (this.props.startInLoadingState) {
417418
this.setState({viewState: WebViewState.LOADING});
418419
}
420+
421+
if (
422+
this.props.useWebKit === true &&
423+
this.props.scalesPageToFit !== undefined
424+
) {
425+
console.warn(
426+
'The scalesPageToFit property is not supported when useWebKit = true',
427+
);
428+
}
419429
}
420430

421431
render() {
422432
let otherView = null;
423433

434+
let scalesPageToFit;
435+
436+
if (this.props.useWebKit) {
437+
({scalesPageToFit} = this.props);
438+
} else {
439+
({scalesPageToFit = true} = this.props);
440+
}
441+
424442
if (this.state.viewState === WebViewState.LOADING) {
425443
otherView = (this.props.renderLoading || defaultRenderLoading)();
426444
} else if (this.state.viewState === WebViewState.ERROR) {
@@ -523,7 +541,7 @@ class WebView extends React.Component {
523541
messagingEnabled={messagingEnabled}
524542
onMessage={this._onMessage}
525543
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
526-
scalesPageToFit={this.props.scalesPageToFit}
544+
scalesPageToFit={scalesPageToFit}
527545
allowsInlineMediaPlayback={this.props.allowsInlineMediaPlayback}
528546
mediaPlaybackRequiresUserAction={
529547
this.props.mediaPlaybackRequiresUserAction
@@ -685,6 +703,12 @@ class WebView extends React.Component {
685703
this._showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
686704
this._showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
687705
this._showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
706+
707+
if (this.props.scalesPageToFit !== undefined) {
708+
console.warn(
709+
'The scalesPageToFit property is not supported when useWebKit = true',
710+
);
711+
}
688712
}
689713

690714
_showRedboxOnPropChanges(prevProps, propName: string) {

0 commit comments

Comments
 (0)