Skip to content

Commit

Permalink
Fix WebView example on iOS
Browse files Browse the repository at this point in the history
Summary: Fixed broken scaling logic in Webview example for iOS. Pages must be reloaded after toggling `scalesPageToFit`, but that wasn't happening.

Reviewed By: javache

Differential Revision: D2982371

fb-gh-sync-id: 8442609179bfe9ade10d1d0bac1807e4a8855d00
shipit-source-id: 8442609179bfe9ade10d1d0bac1807e4a8855d00
  • Loading branch information
nicklockwood authored and Facebook Github Bot 7 committed Feb 26, 2016
1 parent f7df3bb commit 7032a64
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
20 changes: 10 additions & 10 deletions Examples/UIExplorer/WebViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ var WebViewExample = React.createClass({

var Button = React.createClass({
_handlePress: function() {
if (this.props.enabled && this.props.onPress) {
if (this.props.enabled !== false && this.props.onPress) {
this.props.onPress();
}
},
Expand All @@ -182,19 +182,19 @@ var ScaledWebView = React.createClass({

getInitialState: function() {
return {
scalingEnabled: true
scalingEnabled: true,
}
},

render: function() {
return (
<View style={{height:120}}>
<View>
<WebView
style={{
backgroundColor: BGWASH,
height: 100,
height: 200,
}}
source={{html: HTML}}
source={{uri: 'https://facebook.github.io/react/'}}
scalesPageToFit={this.state.scalingEnabled}
/>
<View style={styles.buttons}>
Expand Down Expand Up @@ -307,7 +307,7 @@ const HTML = `
<head>
<title>Hello Static World</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<meta name="viewport" content="width=320, user-scalable=no">
<style type="text/css">
body {
margin: 0;
Expand Down Expand Up @@ -337,6 +337,10 @@ exports.examples = [
title: 'Simple Browser',
render(): ReactElement { return <WebViewExample />; }
},
{
title: 'Scale Page to Fit',
render(): ReactElement { return <ScaledWebView/>; }
},
{
title: 'Bundled HTML',
render(): ReactElement {
Expand Down Expand Up @@ -367,10 +371,6 @@ exports.examples = [
);
}
},
{
title: 'Scale Page to Fit',
render(): ReactElement { return <ScaledWebView/>; }
},
{
title: 'POST Test',
render(): ReactElement {
Expand Down
1 change: 1 addition & 0 deletions React/Views/RCTWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
@property (nonatomic, assign) UIEdgeInsets contentInset;
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
@property (nonatomic, copy) NSString *injectedJavaScript;
@property (nonatomic, assign) BOOL scalesPageToFit;

- (void)goForward;
- (void)goBack;
Expand Down
13 changes: 13 additions & 0 deletions React/Views/RCTWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ - (void)setContentInset:(UIEdgeInsets)contentInset
updateOffset:NO];
}

- (void)setScalesPageToFit:(BOOL)scalesPageToFit
{
if (_webView.scalesPageToFit != scalesPageToFit) {
_webView.scalesPageToFit = scalesPageToFit;
[_webView reload];
}
}

- (BOOL)scalesPageToFit
{
return _webView.scalesPageToFit;
}

- (void)setBackgroundColor:(UIColor *)backgroundColor
{
CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor);
Expand Down
2 changes: 1 addition & 1 deletion React/Views/RCTWebViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary)
RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL)
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, _webView.scrollView.scrollEnabled, BOOL)
RCT_REMAP_VIEW_PROPERTY(scalesPageToFit, _webView.scalesPageToFit, BOOL)
RCT_REMAP_VIEW_PROPERTY(decelerationRate, _webView.scrollView.decelerationRate, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(scalesPageToFit, BOOL)
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString)
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
Expand Down

0 comments on commit 7032a64

Please sign in to comment.