Browse Source

fix:iOS13 scrollView.automaticallyAdjustsScrollIndicatorInsets default value YES which make the webview vertical indicator position in wrong offset

BillHsieh 4 years ago
parent
commit
cc8ad68aa2
2 changed files with 24 additions and 1 deletions
  1. 21
    1
      ios/RNCWebView.m
  2. 3
    0
      ios/RNCWebViewManager.m

+ 21
- 1
ios/RNCWebView.m View File

@@ -67,6 +67,9 @@ static NSDictionary* customCertificatesForHost;
67 67
 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
68 68
   UIScrollViewContentInsetAdjustmentBehavior _savedContentInsetAdjustmentBehavior;
69 69
 #endif
70
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
71
+  BOOL _savedAutomaticallyAdjustsScrollIndicatorInsets;
72
+#endif
70 73
 }
71 74
 
72 75
 - (instancetype)initWithFrame:(CGRect)frame
@@ -87,6 +90,10 @@ static NSDictionary* customCertificatesForHost;
87 90
 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
88 91
     _savedContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
89 92
 #endif
93
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
94
+    _savedAutomaticallyAdjustsScrollIndicatorInsets = NO;
95
+#endif
96
+      
90 97
   }
91 98
 
92 99
   if (@available(iOS 12.0, *)) {
@@ -280,6 +287,9 @@ static NSDictionary* customCertificatesForHost;
280 287
       _webView.scrollView.contentInsetAdjustmentBehavior = _savedContentInsetAdjustmentBehavior;
281 288
     }
282 289
 #endif
290
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
291
+    _webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = _savedAutomaticallyAdjustsScrollIndicatorInsets;
292
+#endif
283 293
 
284 294
     [self addSubview:_webView];
285 295
     [self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
@@ -396,7 +406,17 @@ static NSDictionary* customCertificatesForHost;
396 406
     }
397 407
 }
398 408
 #endif
399
-
409
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
410
+- (void)setAutomaticallyAdjustsScrollIndicatorInsets:(BOOL)automaticallyAdjustsScrollIndicatorInsets{
411
+    _savedAutomaticallyAdjustsScrollIndicatorInsets = automaticallyAdjustsScrollIndicatorInsets;
412
+    if (_webView == nil) {
413
+           return;
414
+       }
415
+       if ([_webView.scrollView respondsToSelector:@selector(setAutomaticallyAdjustsScrollIndicatorInsets:)]) {
416
+           _webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = automaticallyAdjustsScrollIndicatorInsets;
417
+       }
418
+}
419
+#endif
400 420
 /**
401 421
  * This method is called whenever JavaScript running within the web view calls:
402 422
  *   - window.webkit.messageHandlers[MessageHandlerName].postMessage

+ 3
- 0
ios/RNCWebViewManager.m View File

@@ -74,6 +74,9 @@ RCT_EXPORT_VIEW_PROPERTY(allowingReadAccessToURL, NSString)
74 74
 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
75 75
 RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInsetAdjustmentBehavior)
76 76
 #endif
77
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
78
+RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustsScrollIndicatorInsets, BOOL)
79
+#endif
77 80
 
78 81
 /**
79 82
  * Expose methods to enable messaging the webview.