4
4
5
5
@implementation IonicKeyboard
6
6
7
- // @synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
7
+ @synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
8
8
@synthesize disableScroll = _disableScroll;
9
9
// @synthesize styleDark = _styleDark;
10
10
11
11
- (void )pluginInitialize {
12
12
13
- NSNotificationCenter * nc = [NSNotificationCenter defaultCenter ];
14
- __weak IonicKeyboard* weakSelf = self;
15
-
13
+ Class wkClass = NSClassFromString ([@[@" UI" , @" Web" , @" Browser" , @" View" ] componentsJoinedByString: @" " ]);
14
+ wkMethod = class_getInstanceMethod (wkClass, @selector (inputAccessoryView ));
15
+ wkOriginalImp = method_getImplementation (wkMethod);
16
+ Class uiClass = NSClassFromString ([@[@" WK" , @" Content" , @" View" ] componentsJoinedByString: @" " ]);
17
+ uiMethod = class_getInstanceMethod (uiClass, @selector (inputAccessoryView ));
18
+ uiOriginalImp = method_getImplementation (uiMethod);
19
+ nilImp = imp_implementationWithBlock (^(id _s) {
20
+ return nil ;
21
+ });
22
+
16
23
// set defaults
17
- // self.hideKeyboardAccessoryBar = YES;
24
+ self.hideKeyboardAccessoryBar = YES ;
18
25
self.disableScroll = NO ;
19
26
// self.styleDark = NO;
20
-
27
+
28
+ NSNotificationCenter * nc = [NSNotificationCenter defaultCenter ];
29
+ __weak IonicKeyboard* weakSelf = self;
21
30
_keyboardShowObserver = [nc addObserverForName: UIKeyboardWillShowNotification
22
31
object: nil
23
32
queue: [NSOperationQueue mainQueue ]
@@ -42,6 +51,7 @@ - (void)pluginInitialize {
42
51
[weakSelf.commandDelegate evalJs: @" cordova.fireWindowEvent('native.hidekeyboard'); " ];
43
52
}];
44
53
}
54
+
45
55
- (BOOL )disableScroll {
46
56
return _disableScroll;
47
57
}
@@ -62,24 +72,28 @@ - (void)setDisableScroll:(BOOL)disableScroll {
62
72
_disableScroll = disableScroll;
63
73
}
64
74
75
+ // keyboard swizzling inspired by:
76
+ // https://github.com/cjpearson/cordova-plugin-keyboard/
77
+
78
+ - (BOOL )hideKeyboardAccessoryBar {
79
+ return _hideKeyboardAccessoryBar;
80
+ }
65
81
66
- // - (BOOL)hideKeyboardAccessoryBar {
67
- // return _hideKeyboardAccessoryBar;
68
- // }
69
- //
70
- // - (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar {
71
- // if (hideKeyboardAccessoryBar == _hideKeyboardAccessoryBar || ![self.webView isKindOfClass:[UIWebView class]]) {
72
- // return;
73
- // }
74
- // if (hideKeyboardAccessoryBar) {
75
- // ((UIWebView*)self.webView).hackishlyHidesInputAccessoryView = YES;
76
- // }
77
- // else {
78
- // ((UIWebView*)self.webView).hackishlyHidesInputAccessoryView = NO;
79
- // }
80
- //
81
- // _hideKeyboardAccessoryBar = hideKeyboardAccessoryBar;
82
- // }
82
+ - (void )setHideKeyboardAccessoryBar : (BOOL )hideKeyboardAccessoryBar {
83
+ if (hideKeyboardAccessoryBar == _hideKeyboardAccessoryBar) {
84
+ return ;
85
+ }
86
+
87
+ if (hideKeyboardAccessoryBar) {
88
+ method_setImplementation (wkMethod, nilImp);
89
+ method_setImplementation (uiMethod, nilImp);
90
+ } else {
91
+ method_setImplementation (wkMethod, wkOriginalImp);
92
+ method_setImplementation (uiMethod, uiOriginalImp);
93
+ }
94
+
95
+ _hideKeyboardAccessoryBar = hideKeyboardAccessoryBar;
96
+ }
83
97
84
98
/*
85
99
- (BOOL)styleDark {
@@ -129,15 +143,15 @@ - (void) disableScroll:(CDVInvokedUrlCommand*)command {
129
143
}
130
144
}
131
145
132
- // - (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command {
133
- // if (!command.arguments || ![command.arguments count]){
134
- // return;
135
- // }
136
- // id value = [command.arguments objectAtIndex:0];
137
- // if (value != [NSNull null]) {
138
- // self.hideKeyboardAccessoryBar = [value boolValue];
139
- // }
140
- // }
146
+ - (void ) hideKeyboardAccessoryBar : (CDVInvokedUrlCommand*)command {
147
+ if (!command.arguments || ![command.arguments count ]){
148
+ return ;
149
+ }
150
+ id value = [command.arguments objectAtIndex: 0 ];
151
+ if (value != [NSNull null ]) {
152
+ self.hideKeyboardAccessoryBar = [value boolValue ];
153
+ }
154
+ }
141
155
142
156
- (void ) close : (CDVInvokedUrlCommand*)command {
143
157
[self .webView endEditing: YES ];
0 commit comments