diff --git a/AIBHTMLWebView.xcodeproj/project.pbxproj b/AIBHTMLWebView.xcodeproj/project.pbxproj index 9ea06e9..ee34b0f 100644 --- a/AIBHTMLWebView.xcodeproj/project.pbxproj +++ b/AIBHTMLWebView.xcodeproj/project.pbxproj @@ -270,6 +270,11 @@ E236CCE81AD173A500D5FC85 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(PROJECT_DIR)/../react-native/**", + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -280,6 +285,11 @@ E236CCE91AD173A500D5FC85 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(PROJECT_DIR)/../react-native/**", + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/iOS/AIBHTMLWebView.m b/iOS/AIBHTMLWebView.m index 67414dc..bcbb927 100644 --- a/iOS/AIBHTMLWebView.m +++ b/iOS/AIBHTMLWebView.m @@ -21,6 +21,7 @@ @implementation AIBHTMLWebView { RCTEventDispatcher *_eventDispatcher; UIWebView *_webView; + BOOL autoHeight; } - (void)setHTML:(NSString *)HTML @@ -30,9 +31,10 @@ - (void)setHTML:(NSString *)HTML [self reportHeight]; } -- (void)setEnableScroll:(BOOL) enable +- (void)setAutoHeight:(BOOL) enable { - _webView.scrollView.scrollEnabled = enable; + _webView.scrollView.scrollEnabled = !enable; + autoHeight = enable; } - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher @@ -42,6 +44,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher _webView = [[UIWebView alloc] initWithFrame:self.bounds]; _webView.delegate = self; [self addSubview:_webView]; + autoHeight = false; } return self; } @@ -55,12 +58,21 @@ - (void)layoutSubviews - (void)reportHeight { - NSNumber *height =[NSNumber numberWithFloat: _webView.scrollView.contentSize.height]; + if (!autoHeight) { + return; + } + CGRect frame = _webView.frame; + frame.size.height = 1; + _webView.frame = frame; + frame.size.height = [[_webView stringByEvaluatingJavaScriptFromString: @"document.documentElement.scrollHeight"] floatValue]; + NSNumber *height = [NSNumber numberWithFloat: frame.size.height]; + NSMutableDictionary *event = [[NSMutableDictionary alloc] initWithDictionary: @{ @"target": self.reactTag, @"contentHeight": height }]; - [_eventDispatcher sendInputEventWithName:@"contentHeight" body:event]; + [_eventDispatcher sendInputEventWithName:@"changeHeight" body:event]; + _webView.frame = frame; } #pragma mark - UIWebViewDelegate methods diff --git a/iOS/AIBHTMLWebViewManager.m b/iOS/AIBHTMLWebViewManager.m index f6c5098..a11a396 100644 --- a/iOS/AIBHTMLWebViewManager.m +++ b/iOS/AIBHTMLWebViewManager.m @@ -17,7 +17,7 @@ @implementation AIBHTMLWebViewManager RCT_EXPORT_MODULE(); RCT_REMAP_VIEW_PROPERTY(html, HTML, NSString) -RCT_EXPORT_VIEW_PROPERTY(enableScroll, BOOL) +RCT_EXPORT_VIEW_PROPERTY(autoHeight, BOOL) - (UIView *)view { @@ -32,8 +32,8 @@ - (NSDictionary *)customDirectEventTypes @"link": @{ @"registrationName": @"onLink" }, - @"contentHeight": @{ - @"registrationName": @"onContentHeight" + @"changeHeight": @{ + @"registrationName": @"onChangeHeight" } }; } diff --git a/index.ios.js b/index.ios.js index 3d1635c..9fcc8cf 100644 --- a/index.ios.js +++ b/index.ios.js @@ -16,7 +16,7 @@ var _ = require('underscore'); var _HTMLWebView = React.createClass({ propTypes: { html: PropTypes.string, - enableScroll: PropTypes.bool + autoHeight: PropTypes.bool }, render: function () { return ; @@ -36,7 +36,7 @@ var HTMLWebView = React.createClass({ }, componentWillMount: function () { - this.onContentHeight = _.throttle(this.onContentHeight, 300); + this.onChangeHeight = _.throttle(this.onChangeHeight, 300); }, shouldComponentUpdate: function (nextProps, nextState) { @@ -62,12 +62,12 @@ var HTMLWebView = React.createClass({ <_HTMLWebView style={[{height: this.state.contentHeight}, this.props.style]} html={this._safeHtml} - enableScroll={!this.props.autoHeight} + autoHeight={this.props.autoHeight} onLink={this.onLink} - onContentHeight={(e) => { + onChangeHeight={(e) => { this.contentHeight = e.nativeEvent.contentHeight; if (this.props.autoHeight && this.contentHeight > 1) { - this.onContentHeight(); + this.onChangeHeight(); } }} /> ); @@ -90,7 +90,7 @@ var HTMLWebView = React.createClass({ } }, - onContentHeight: function () { + onChangeHeight: function () { if (this.contentHeight !== this.state.contentHeight) { this.setState({contentHeight: this.contentHeight}); } diff --git a/package.json b/package.json index bc35831..4658f60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-html-webview", - "version": "0.0.9", + "version": "0.0.10", "description": "Display (possibly untrusted) HTML using a UIWebView in React Native.", "main": "index.ios.js", "scripts": { @@ -28,6 +28,6 @@ "react-native": "^0.4.4" }, "dependencies": { - "safe-html": "0.0.2" + "safe-html": "0.0.3" } }