Browse Source

Implement scrollEnabled for mac.

Tom Underhill 4 years ago
parent
commit
ba1be12ea0
1 changed files with 24 additions and 0 deletions
  1. 24
    0
      ios/RNCWebView.m

+ 24
- 0
ios/RNCWebView.m View File

42
 @end
42
 @end
43
 #endif // !TARGET_OS_OSX
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
 @interface RNCWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler,
60
 @interface RNCWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler,
46
 #if !TARGET_OS_OSX
61
 #if !TARGET_OS_OSX
47
     UIScrollViewDelegate,
62
     UIScrollViewDelegate,
56
 @property (nonatomic, copy) RCTDirectEventBlock onMessage;
71
 @property (nonatomic, copy) RCTDirectEventBlock onMessage;
57
 @property (nonatomic, copy) RCTDirectEventBlock onScroll;
72
 @property (nonatomic, copy) RCTDirectEventBlock onScroll;
58
 @property (nonatomic, copy) RCTDirectEventBlock onContentProcessDidTerminate;
73
 @property (nonatomic, copy) RCTDirectEventBlock onContentProcessDidTerminate;
74
+#if !TARGET_OS_OSX
59
 @property (nonatomic, copy) WKWebView *webView;
75
 @property (nonatomic, copy) WKWebView *webView;
76
+#else
77
+@property (nonatomic, copy) RNCWKWebView *webView;
78
+#endif // !TARGET_OS_OSX
60
 @end
79
 @end
61
 
80
 
62
 @implementation RNCWebView
81
 @implementation RNCWebView
298
       }
317
       }
299
     }
318
     }
300
 
319
 
320
+#if !TARGET_OS_OSX
301
     _webView = [[WKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
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
     [self setBackgroundColor: _savedBackgroundColor];
326
     [self setBackgroundColor: _savedBackgroundColor];
303
 #if !TARGET_OS_OSX
327
 #if !TARGET_OS_OSX
304
     _webView.scrollView.delegate = self;
328
     _webView.scrollView.delegate = self;