瀏覽代碼

fix(WKWebview Scroll): Don't allow the scrollView to scroll when `scrollEnabled={false}`. (#158)

* Don't allow the scrollview to scroll the WebView body.

* Readme comment

* Remove duplicate protocol def
Chet Corcos 6 年之前
父節點
當前提交
0e6e92a7f1
共有 2 個檔案被更改,包括 14 行新增1 行删除
  1. 1
    1
      docs/Reference.md
  2. 13
    0
      ios/RNCWKWebView.m

+ 1
- 1
docs/Reference.md 查看文件

446
 
446
 
447
 ### `scrollEnabled`
447
 ### `scrollEnabled`
448
 
448
 
449
-Boolean value that determines whether scrolling is enabled in the `WebView`. The default value is `true`.
449
+Boolean value that determines whether scrolling is enabled in the `WebView`. The default value is `true`. Setting this to `false` will prevent the webview from moving the document body when the keyboard appears over an input.
450
 
450
 
451
 | Type | Required | Platform |
451
 | Type | Required | Platform |
452
 | ---- | -------- | -------- |
452
 | ---- | -------- | -------- |

+ 13
- 0
ios/RNCWKWebView.m 查看文件

341
 {
341
 {
342
   _scrollEnabled = scrollEnabled;
342
   _scrollEnabled = scrollEnabled;
343
   _webView.scrollView.scrollEnabled = scrollEnabled;
343
   _webView.scrollView.scrollEnabled = scrollEnabled;
344
+
345
+  // Override the scrollView delegate to prevent scrolling.
346
+  if (!scrollEnabled) {
347
+    _webView.scrollView.delegate = self;
348
+  } else {
349
+    _webView.scrollView.delegate = _webView;
350
+  }
351
+}
352
+
353
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView
354
+{
355
+  // Don't allow scrolling the scrollView.
356
+  scrollView.bounds = _webView.bounds;
344
 }
357
 }
345
 
358
 
346
 - (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator
359
 - (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator