@@ -40,15 +40,29 @@ - (id)settingForKey:(NSString*)key
4040
4141#pragma mark Initialize
4242
43+ static NSString * UIClassString;
44+ static NSString * WKClassString;
45+ static NSString * UITraitsClassString;
46+
4347- (void )pluginInitialize
4448{
49+ // Create these strings at runtime so they aren't flagged
50+ UIClassString = [@[@" UI" , @" Web" , @" Browser" , @" View" ] componentsJoinedByString: @" " ];
51+ WKClassString = [@[@" WK" , @" Content" , @" View" ] componentsJoinedByString: @" " ];
52+ UITraitsClassString = [@[@" UI" , @" Text" , @" Input" , @" Traits" ] componentsJoinedByString: @" " ];
53+
4554 NSString * setting = nil ;
4655
4756 setting = @" HideKeyboardFormAccessoryBar" ;
4857 if ([self settingForKey: setting]) {
4958 self.hideFormAccessoryBar = [(NSNumber *)[self settingForKey: setting] boolValue ];
5059 }
5160
61+ setting = @" KeyboardStyle" ;
62+ if ([self settingForKey: setting]) {
63+ self.keyboardStyle = [self settingForKey: setting];
64+ }
65+
5266 setting = @" KeyboardShrinksView" ;
5367 if ([self settingForKey: setting]) {
5468 self.shrinkView = [(NSNumber *)[self settingForKey: setting] boolValue ];
@@ -66,28 +80,28 @@ - (void)pluginInitialize
6680 object: nil
6781 queue: [NSOperationQueue mainQueue ]
6882 usingBlock: ^(NSNotification * notification) {
69- [weakSelf.commandDelegate evalJs: @" Keyboard.fireOnShow();" ];
83+ [weakSelf.commandDelegate evalJs: @" Keyboard.fireOnShow();" ];
7084 }];
7185 _keyboardHideObserver = [nc addObserverForName: UIKeyboardDidHideNotification
7286 object: nil
7387 queue: [NSOperationQueue mainQueue ]
7488 usingBlock: ^(NSNotification * notification) {
75- [weakSelf.commandDelegate evalJs: @" Keyboard.fireOnHide();" ];
89+ [weakSelf.commandDelegate evalJs: @" Keyboard.fireOnHide();" ];
7690 }];
7791
7892 _keyboardWillShowObserver = [nc addObserverForName: UIKeyboardWillShowNotification
7993 object: nil
8094 queue: [NSOperationQueue mainQueue ]
8195 usingBlock: ^(NSNotification * notification) {
82- [weakSelf.commandDelegate evalJs: @" Keyboard.fireOnShowing();" ];
83- weakSelf.keyboardIsVisible = YES ;
96+ [weakSelf.commandDelegate evalJs: @" Keyboard.fireOnShowing();" ];
97+ weakSelf.keyboardIsVisible = YES ;
8498 }];
8599 _keyboardWillHideObserver = [nc addObserverForName: UIKeyboardWillHideNotification
86100 object: nil
87101 queue: [NSOperationQueue mainQueue ]
88102 usingBlock: ^(NSNotification * notification) {
89- [weakSelf.commandDelegate evalJs: @" Keyboard.fireOnHiding();" ];
90- weakSelf.keyboardIsVisible = NO ;
103+ [weakSelf.commandDelegate evalJs: @" Keyboard.fireOnHiding();" ];
104+ weakSelf.keyboardIsVisible = NO ;
91105 }];
92106
93107 _shrinkViewKeyboardWillChangeFrameObserver = [nc addObserverForName: UIKeyboardWillChangeFrameNotification
@@ -121,9 +135,6 @@ - (void)setHideFormAccessoryBar:(BOOL)ahideFormAccessoryBar
121135 return ;
122136 }
123137
124- NSString * UIClassString = [@[@" UI" , @" Web" , @" Browser" , @" View" ] componentsJoinedByString: @" " ];
125- NSString * WKClassString = [@[@" WK" , @" Content" , @" View" ] componentsJoinedByString: @" " ];
126-
127138 Method UIMethod = class_getInstanceMethod (NSClassFromString (UIClassString), @selector (inputAccessoryView ));
128139 Method WKMethod = class_getInstanceMethod (NSClassFromString (WKClassString), @selector (inputAccessoryView ));
129140
@@ -145,6 +156,39 @@ - (void)setHideFormAccessoryBar:(BOOL)ahideFormAccessoryBar
145156 _hideFormAccessoryBar = ahideFormAccessoryBar;
146157}
147158
159+ #pragma mark Keyboard Style
160+
161+ - (NSString *)keyboardStyle
162+ {
163+ return _keyboardStyle;
164+ }
165+
166+ - (void )setKeyboardStyle : (NSString *)style
167+ {
168+ if ([style isEqualToString: _keyboardStyle]) {
169+ return ;
170+ }
171+
172+ IMP newImp = [style isEqualToString: @" dark" ] ? imp_implementationWithBlock (^(id _s) {
173+ return UIKeyboardAppearanceDark;
174+ }) : imp_implementationWithBlock (^(id _s) {
175+ return UIKeyboardAppearanceLight;
176+ });
177+
178+ for (NSString * classString in @[UIClassString, UITraitsClassString]) {
179+ Class c = NSClassFromString (classString);
180+ Method m = class_getInstanceMethod (c, @selector (keyboardAppearance ));
181+
182+ if (m != NULL ) {
183+ method_setImplementation (m, newImp);
184+ } else {
185+ class_addMethod (c, @selector (keyboardAppearance ), newImp, " l@:" );
186+ }
187+ }
188+
189+ _keyboardStyle = style;
190+ }
191+
148192#pragma mark KeyboardShrinksView
149193
150194- (void )shrinkViewKeyboardWillChangeFrame : (NSNotification *)notif
@@ -238,6 +282,18 @@ - (void)hideFormAccessoryBar:(CDVInvokedUrlCommand*)command
238282 self.hideFormAccessoryBar = [value boolValue ];
239283}
240284
285+ - (void )keyboardStyle : (CDVInvokedUrlCommand*)command
286+ {
287+ id value = [command.arguments objectAtIndex: 0 ];
288+ if ([value isKindOfClass: [NSString class ]]) {
289+ value = [(NSString *)value lowercaseString ];
290+ } else {
291+ value = @" light" ;
292+ }
293+
294+ self.keyboardStyle = value;
295+ }
296+
241297- (void )hide : (CDVInvokedUrlCommand*)command
242298{
243299 [self .webView endEditing: YES ];
0 commit comments