Parcourir la source

Implement scrollEnabled for mac.

Tom Underhill il y a 4 ans
Parent
révision
ba1be12ea0
1 fichiers modifiés avec 24 ajouts et 0 suppressions
  1. 24
    0
      ios/RNCWebView.m

+ 24
- 0
ios/RNCWebView.m Voir le fichier

@@ -42,6 +42,21 @@ static NSDictionary* customCertificatesForHost;
42 42
 @end
43 43
 #endif // !TARGET_OS_OSX
44 44
 
45
+#if TARGET_OS_OSX
46
+@interface RNCWKWebView : WKWebView
47
+@end
48
+@implementation RNCWKWebView
49
+- (void)scrollWheel:(NSEvent *)theEvent {
50
+  RNCWebView *rncWebView = (RNCWebView *)[self superview];
51
+  if (![rncWebView scrollEnabled]) {
52
+    [[self nextResponder] scrollWheel:theEvent];
53
+    return;
54
+  }
55
+  [super scrollWheel:theEvent];
56
+}
57
+@end
58
+#endif // TARGET_OS_OSX
59
+
45 60
 @interface RNCWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler,
46 61
 #if !TARGET_OS_OSX
47 62
     UIScrollViewDelegate,
@@ -56,7 +71,11 @@ static NSDictionary* customCertificatesForHost;
56 71
 @property (nonatomic, copy) RCTDirectEventBlock onMessage;
57 72
 @property (nonatomic, copy) RCTDirectEventBlock onScroll;
58 73
 @property (nonatomic, copy) RCTDirectEventBlock onContentProcessDidTerminate;
74
+#if !TARGET_OS_OSX
59 75
 @property (nonatomic, copy) WKWebView *webView;
76
+#else
77
+@property (nonatomic, copy) RNCWKWebView *webView;
78
+#endif // !TARGET_OS_OSX
60 79
 @end
61 80
 
62 81
 @implementation RNCWebView
@@ -298,7 +317,12 @@ static NSDictionary* customCertificatesForHost;
298 317
       }
299 318
     }
300 319
 
320
+#if !TARGET_OS_OSX
301 321
     _webView = [[WKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
322
+#else
323
+    _webView = [[RNCWKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
324
+#endif // !TARGET_OS_OSX
325
+
302 326
     [self setBackgroundColor: _savedBackgroundColor];
303 327
 #if !TARGET_OS_OSX
304 328
     _webView.scrollView.delegate = self;