|
25 | 25 | //source: http://stackoverflow.com/a/23387659/828487
|
26 | 26 | #define NSStringMultiline(...) [[NSString alloc] initWithCString:#__VA_ARGS__ encoding:NSUTF8StringEncoding]
|
27 | 27 |
|
28 |
| - |
29 | 28 | //we don'e need this one since it has been defined in RCTWebView.m
|
30 | 29 | //NSString *const RCTJSNavigationScheme = @"react-js-navigation";
|
31 | 30 | NSString *const RCTWebViewBridgeSchema = @"wvb";
|
32 | 31 |
|
| 32 | +// runtime trick to remove UIWebview keyboard default toolbar |
| 33 | +// see: http://stackoverflow.com/questions/19033292/ios-7-uiwebview-keyboard-issue/19042279#19042279 |
| 34 | +@interface _SwizzleHelper : NSObject @end |
| 35 | +@implementation _SwizzleHelper |
| 36 | +-(id)inputAccessoryView |
| 37 | +{ |
| 38 | + return nil; |
| 39 | +} |
| 40 | +@end |
| 41 | + |
33 | 42 | @interface RCTWebViewBridge () <UIWebViewDelegate, RCTAutoInsetsProtocol>
|
34 | 43 |
|
35 | 44 | @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
|
@@ -165,6 +174,37 @@ - (void)refreshContentInset
|
165 | 174 | updateOffset:YES];
|
166 | 175 | }
|
167 | 176 |
|
| 177 | +-(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView |
| 178 | +{ |
| 179 | + if (!hideKeyboardAccessoryView) { |
| 180 | + return; |
| 181 | + } |
| 182 | + |
| 183 | + UIView* subview; |
| 184 | + for (UIView* view in _webView.scrollView.subviews) { |
| 185 | + if([[view.class description] hasPrefix:@"UIWeb"]) |
| 186 | + subview = view; |
| 187 | + } |
| 188 | + |
| 189 | + if(subview == nil) return; |
| 190 | + |
| 191 | + NSString* name = [NSString stringWithFormat:@"%@_SwizzleHelper", subview.class.superclass]; |
| 192 | + Class newClass = NSClassFromString(name); |
| 193 | + |
| 194 | + if(newClass == nil) |
| 195 | + { |
| 196 | + newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0); |
| 197 | + if(!newClass) return; |
| 198 | + |
| 199 | + Method method = class_getInstanceMethod([_SwizzleHelper class], @selector(inputAccessoryView)); |
| 200 | + class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method)); |
| 201 | + |
| 202 | + objc_registerClassPair(newClass); |
| 203 | + } |
| 204 | + |
| 205 | + object_setClass(subview, newClass); |
| 206 | +} |
| 207 | + |
168 | 208 | #pragma mark - UIWebViewDelegate methods
|
169 | 209 |
|
170 | 210 | - (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
|
|
0 commit comments