|
@@ -9,8 +9,20 @@
|
9
|
9
|
#import <React/RCTConvert.h>
|
10
|
10
|
#import <React/RCTAutoInsetsProtocol.h>
|
11
|
11
|
|
|
12
|
+#import "objc/runtime.h"
|
|
13
|
+
|
12
|
14
|
static NSString *const MessageHanderName = @"ReactNative";
|
13
|
15
|
|
|
16
|
+// runtime trick to remove WKWebView keyboard default toolbar
|
|
17
|
+// see: http://stackoverflow.com/questions/19033292/ios-7-uiwebview-keyboard-issue/19042279#19042279
|
|
18
|
+@interface _SwizzleHelperWK : NSObject @end
|
|
19
|
+@implementation _SwizzleHelperWK
|
|
20
|
+-(id)inputAccessoryView
|
|
21
|
+{
|
|
22
|
+ return nil;
|
|
23
|
+}
|
|
24
|
+@end
|
|
25
|
+
|
14
|
26
|
@interface RNCWKWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, UIScrollViewDelegate, RCTAutoInsetsProtocol>
|
15
|
27
|
@property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
|
16
|
28
|
@property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
|
|
@@ -24,6 +36,7 @@ static NSString *const MessageHanderName = @"ReactNative";
|
24
|
36
|
@implementation RNCWKWebView
|
25
|
37
|
{
|
26
|
38
|
UIColor * _savedBackgroundColor;
|
|
39
|
+ BOOL _savedHideKeyboardAccessoryView;
|
27
|
40
|
}
|
28
|
41
|
|
29
|
42
|
- (void)dealloc
|
|
@@ -97,7 +110,7 @@ static NSString *const MessageHanderName = @"ReactNative";
|
97
|
110
|
#endif
|
98
|
111
|
|
99
|
112
|
[self addSubview:_webView];
|
100
|
|
-
|
|
113
|
+ [self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
|
101
|
114
|
[self visitSource];
|
102
|
115
|
} else {
|
103
|
116
|
[_webView.configuration.userContentController removeScriptMessageHandlerForName:MessageHanderName];
|
|
@@ -198,6 +211,42 @@ static NSString *const MessageHanderName = @"ReactNative";
|
198
|
211
|
[_webView loadRequest:request];
|
199
|
212
|
}
|
200
|
213
|
|
|
214
|
+-(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
|
|
215
|
+{
|
|
216
|
+
|
|
217
|
+ if (_webView == nil) {
|
|
218
|
+ _savedHideKeyboardAccessoryView = hideKeyboardAccessoryView;
|
|
219
|
+ return;
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ if (_savedHideKeyboardAccessoryView == false) {
|
|
223
|
+ return;
|
|
224
|
+ }
|
|
225
|
+
|
|
226
|
+ UIView* subview;
|
|
227
|
+ for (UIView* view in _webView.scrollView.subviews) {
|
|
228
|
+ if([[view.class description] hasPrefix:@"WK"])
|
|
229
|
+ subview = view;
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ if(subview == nil) return;
|
|
233
|
+
|
|
234
|
+ NSString* name = [NSString stringWithFormat:@"%@_SwizzleHelperWK", subview.class.superclass];
|
|
235
|
+ Class newClass = NSClassFromString(name);
|
|
236
|
+
|
|
237
|
+ if(newClass == nil)
|
|
238
|
+ {
|
|
239
|
+ newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0);
|
|
240
|
+ if(!newClass) return;
|
|
241
|
+
|
|
242
|
+ Method method = class_getInstanceMethod([_SwizzleHelperWK class], @selector(inputAccessoryView));
|
|
243
|
+ class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));
|
|
244
|
+
|
|
245
|
+ objc_registerClassPair(newClass);
|
|
246
|
+ }
|
|
247
|
+
|
|
248
|
+ object_setClass(subview, newClass);
|
|
249
|
+}
|
201
|
250
|
|
202
|
251
|
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
203
|
252
|
{
|