Kaynağa Gözat

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 5 yıl önce
ebeveyn
işleme
0e6e92a7f1
2 değiştirilmiş dosya ile 14 ekleme ve 1 silme
  1. 1
    1
      docs/Reference.md
  2. 13
    0
      ios/RNCWKWebView.m

+ 1
- 1
docs/Reference.md Dosyayı Görüntüle

@@ -446,7 +446,7 @@ With the [new WebKit](Reference.md#usewebkit) implementation, we have three new
446 446
 
447 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 451
 | Type | Required | Platform |
452 452
 | ---- | -------- | -------- |

+ 13
- 0
ios/RNCWKWebView.m Dosyayı Görüntüle

@@ -341,6 +341,19 @@ static NSURLCredential* clientAuthenticationCredential;
341 341
 {
342 342
   _scrollEnabled = scrollEnabled;
343 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 359
 - (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator