@@ -53,8 +53,17 @@ - (id)settingForKey:(NSString *)key
5353
5454#pragma mark Initialize
5555
56+ NSString * UIClassString;
57+ NSString * WKClassString;
58+ NSString * UITraitsClassString;
59+ NSString * _keyboardStyle;
60+
5661- (void )pluginInitialize
5762{
63+ UIClassString = [@[@" UI" , @" Web" , @" Browser" , @" View" ] componentsJoinedByString: @" " ];
64+ WKClassString = [@[@" WK" , @" Content" , @" View" ] componentsJoinedByString: @" " ];
65+ UITraitsClassString = [@[@" UI" , @" Text" , @" Input" , @" Traits" ] componentsJoinedByString: @" " ];
66+
5867 NSDictionary *settings = self.commandDelegate .settings ;
5968
6069 [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (statusBarDidChangeFrame: ) name: UIApplicationDidChangeStatusBarFrameNotification object: nil ];
@@ -74,10 +83,17 @@ - (void)pluginInitialize
7483 self.keyboardResizes = ResizeBody;
7584 }
7685 }
77- NSLog (@" CDVIonicKeyboard: resize mode %d " , self.keyboardResizes );
86+ NSLog (@" CDVIonicKeyboard: resize mode %lu " , ( unsigned long ) self.keyboardResizes );
7887 }
7988 self.hideFormAccessoryBar = [settings cordovaBoolSettingForKey: @" HideKeyboardFormAccessoryBar" defaultValue: YES ];
8089
90+ // get the KeyboardStyle value from config.xml
91+ NSString *keyboardStyle = [settings cordovaSettingForKey: @" KeyboardStyle" ];
92+ if (keyboardStyle) {
93+ // call to setKeyboardStyle
94+ [self setKeyboardStyle: keyboardStyle];
95+ }
96+
8197 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter ];
8298
8399 [nc addObserver: self selector: @selector (onKeyboardWillHide: ) name: UIKeyboardWillHideNotification object: nil ];
@@ -139,6 +155,9 @@ - (void)onKeyboardWillShow:(NSNotification *)note
139155 [self setKeyboardHeight: height delay: duration+0.2 ];
140156 [self resetScrollView ];
141157 }
158+
159+ // call to setKeyboardStyle in case it's changed
160+ [self setKeyboardStyle: self .keyboardStyle];
142161
143162 NSString *js = [NSString stringWithFormat: @" Keyboard.fireOnShowing(%d );" , (int )height];
144163 [self .commandDelegate evalJs: js];
@@ -228,6 +247,48 @@ - (void)_updateFrame
228247 [self resetScrollView ];
229248}
230249
250+ #pragma mark Keyboard Style
251+
252+ - (NSString *)keyboardStyle
253+ {
254+ return _keyboardStyle;
255+ }
256+
257+ - (void )setKeyboardStyle:(NSString *)style
258+ {
259+ IMP newImp = [style isEqualToString: @" dark" ] ? imp_implementationWithBlock (^(id _s) {
260+ return UIKeyboardAppearanceDark;
261+ }) : imp_implementationWithBlock (^(id _s) {
262+ return UIKeyboardAppearanceLight;
263+ });
264+
265+ if (self.isWK ) {
266+ for (NSString * classString in @[WKClassString, UITraitsClassString]) {
267+ Class c = NSClassFromString (classString);
268+ Method m = class_getInstanceMethod (c, @selector (keyboardAppearance ));
269+
270+ if (m != NULL ) {
271+ method_setImplementation (m, newImp);
272+ } else {
273+ class_addMethod (c, @selector (keyboardAppearance ), newImp, " l@:" );
274+ }
275+ }
276+ }
277+ else {
278+ for (NSString * classString in @[UIClassString, UITraitsClassString]) {
279+ Class c = NSClassFromString (classString);
280+ Method m = class_getInstanceMethod (c, @selector (keyboardAppearance ));
281+
282+ if (m != NULL ) {
283+ method_setImplementation (m, newImp);
284+ } else {
285+ class_addMethod (c, @selector (keyboardAppearance ), newImp, " l@:" );
286+ }
287+ }
288+ }
289+
290+ _keyboardStyle = style;
291+ }
231292
232293#pragma mark HideFormAccessoryBar
233294
@@ -240,9 +301,6 @@ - (void)setHideFormAccessoryBar:(BOOL)hideFormAccessoryBar
240301 return ;
241302 }
242303
243- NSString * UIClassString = [@[@" UI" , @" Web" , @" Browser" , @" View" ] componentsJoinedByString: @" " ];
244- NSString * WKClassString = [@[@" WK" , @" Content" , @" View" ] componentsJoinedByString: @" " ];
245-
246304 Method UIMethod = class_getInstanceMethod (NSClassFromString (UIClassString), @selector (inputAccessoryView ));
247305 Method WKMethod = class_getInstanceMethod (NSClassFromString (WKClassString), @selector (inputAccessoryView ));
248306
@@ -301,6 +359,17 @@ -(void)setResizeMode:(CDVInvokedUrlCommand *)command
301359 }
302360}
303361
362+ - (void )keyboardStyle : (CDVInvokedUrlCommand*)command
363+ {
364+ id value = [command.arguments objectAtIndex: 0 ];
365+ if ([value isKindOfClass: [NSString class ]]) {
366+ value = [(NSString *)value lowercaseString ];
367+ } else {
368+ value = @" light" ;
369+ }
370+
371+ self.keyboardStyle = value;
372+ }
304373
305374#pragma mark dealloc
306375
0 commit comments