소스 검색

Updated keyboardDisplacementFix on RNCWKWebView

Catch some edge cases where the scrollView contentSize might be smaller than the frame size
Updated if code style (added spaces)
Alexander Stammbach 6 년 전
부모
커밋
831f8f4442
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5
    2
      ios/RNCWKWebView.m

+ 5
- 2
ios/RNCWKWebView.m 파일 보기

177
     // Additional viewport checks to prevent unintentional scrolls
177
     // Additional viewport checks to prevent unintentional scrolls
178
     UIScrollView *scrollView = self.webView.scrollView;
178
     UIScrollView *scrollView = self.webView.scrollView;
179
     double maxContentOffset = scrollView.contentSize.height - scrollView.frame.size.height;
179
     double maxContentOffset = scrollView.contentSize.height - scrollView.frame.size.height;
180
-    if(scrollView.contentOffset.y > maxContentOffset) {
180
+    if (maxContentOffset < 0) {
181
+        maxContentOffset = 0;
182
+    }
183
+    if (scrollView.contentOffset.y > maxContentOffset) {
181
       // https://stackoverflow.com/a/9637807/824966
184
       // https://stackoverflow.com/a/9637807/824966
182
       [UIView animateWithDuration:.25 animations:^{
185
       [UIView animateWithDuration:.25 animations:^{
183
-          self.webView.scrollView.contentOffset = CGPointMake(0, maxContentOffset);
186
+          scrollView.contentOffset = CGPointMake(0, maxContentOffset);
184
       }];
187
       }];
185
     }
188
     }
186
 }
189
 }