Skip to content
This repository was archived by the owner on Apr 2, 2018. It is now read-only.

Commit b1436e3

Browse files
committed
add styleDark
1 parent 90b0528 commit b1436e3

File tree

6 files changed

+95
-21
lines changed

6 files changed

+95
-21
lines changed

plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535

3636
<header-file src="src/ios/IonicKeyboard.h" />
3737
<source-file src="src/ios/IonicKeyboard.m" />
38-
<header-file src="src/ios/UIWebViewAccessoryHiding.h" />
39-
<source-file src="src/ios/UIWebViewAccessoryHiding.m" />
38+
<header-file src="src/ios/UIWebViewExtension.h" />
39+
<source-file src="src/ios/UIWebViewExtension.m" />
4040
</platform>
4141

4242
</plugin>

src/ios/IonicKeyboard.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
id _keyboardShowObserver, _keyboardHideObserver;
66
}
77

8-
@property (readwrite, assign, getter = hideKeyboardAccessoryBar, setter = setHideKeyboardAccessoryBar:) BOOL hideKeyboardAccessoryBar;
8+
@property (readwrite, assign) BOOL hideKeyboardAccessoryBar;
99
@property (readwrite, assign) BOOL disableScroll;
10-
11-
- (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command;
12-
- (void) close:(CDVInvokedUrlCommand*)command;
10+
@property (readwrite, assign) BOOL styleDark;
1311

1412
@end
1513

src/ios/IonicKeyboard.m

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#import "IonicKeyboard.h"
2-
#import "UIWebViewAccessoryHiding.h"
2+
#import "UIWebViewExtension.h"
33
#import <Cordova/CDVAvailability.h>
44

55
@implementation IonicKeyboard
66

77
@synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
88
@synthesize disableScroll = _disableScroll;
9+
@synthesize styleDark = _styleDark;
910

10-
- (void)pluginInitialize
11-
{
11+
- (void)pluginInitialize {
1212

1313
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
1414
__weak IonicKeyboard* weakSelf = self;
1515

1616
//set defaults
1717
self.hideKeyboardAccessoryBar = NO;
1818
self.disableScroll = NO;
19-
19+
self.styleDark = NO;
20+
2021
_keyboardShowObserver = [nc addObserverForName:UIKeyboardWillShowNotification
2122
object:nil
2223
queue:[NSOperationQueue mainQueue]
@@ -37,17 +38,15 @@ - (void)pluginInitialize
3738
[weakSelf.commandDelegate evalJs:@"cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.hidekeyboard'); "];
3839
}];
3940
}
40-
- (BOOL)disableScroll
41-
{
41+
- (BOOL)disableScroll {
4242
return _disableScroll;
4343
}
4444

45-
- (void)setDisableScroll:(BOOL)disableScroll
46-
{
45+
- (void)setDisableScroll:(BOOL)disableScroll {
4746
if (disableScroll == _disableScroll) {
4847
return;
4948
}
50-
if (disableScroll){
49+
if (disableScroll) {
5150
self.webView.scrollView.scrollEnabled = NO;
5251
self.webView.scrollView.delegate = self;
5352
}
@@ -60,17 +59,15 @@ - (void)setDisableScroll:(BOOL)disableScroll
6059
}
6160

6261

63-
- (BOOL)hideKeyboardAccessoryBar
64-
{
62+
- (BOOL)hideKeyboardAccessoryBar {
6563
return _hideKeyboardAccessoryBar;
6664
}
6765

68-
- (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar
69-
{
66+
- (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar {
7067
if (hideKeyboardAccessoryBar == _hideKeyboardAccessoryBar) {
7168
return;
7269
}
73-
if (hideKeyboardAccessoryBar){
70+
if (hideKeyboardAccessoryBar) {
7471
self.webView.hackishlyHidesInputAccessoryView = YES;
7572
}
7673
else {
@@ -80,6 +77,24 @@ - (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar
8077
_hideKeyboardAccessoryBar = hideKeyboardAccessoryBar;
8178
}
8279

80+
- (BOOL)styleDark {
81+
return _styleDark;
82+
}
83+
84+
- (void)setStyleDark:(BOOL)styleDark {
85+
if (styleDark == _styleDark) {
86+
return;
87+
}
88+
if (styleDark) {
89+
self.webView.styleDark = YES;
90+
}
91+
else {
92+
self.webView.styleDark = NO;
93+
}
94+
95+
_styleDark = styleDark;
96+
}
97+
8398

8499
/* ------------------------------------------------------------- */
85100

@@ -125,5 +140,15 @@ - (void) close:(CDVInvokedUrlCommand*)command
125140
[self.webView endEditing:YES];
126141
}
127142

143+
- (void) styleDark:(CDVInvokedUrlCommand*)command
144+
{
145+
if (!command.arguments || ![command.arguments count]){
146+
return;
147+
}
148+
id value = [command.arguments objectAtIndex:0];
149+
150+
self.styleDark = [value boolValue];
151+
}
152+
128153
@end
129154

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@interface UIWebView (HackishAccessoryHiding)
22
@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView;
3+
@property (nonatomic, assign) BOOL styleDark;
34
@end
Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#import <objc/runtime.h>
22
#import <UIKit/UIKit.h>
3-
#import "UIWebViewAccessoryHiding.h"
3+
#import "UIWebViewExtension.h"
44

55
//Credit: https://gist.github.com/bjhomer/2048571
6+
//Also: http://stackoverflow.com/a/23398487/1091751
67
@implementation UIWebView (HackishAccessoryHiding)
78

89
static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView";
@@ -57,5 +58,50 @@ - (void) setHackishlyHidesInputAccessoryView:(BOOL)value {
5758
}
5859
[browserView reloadInputViews];
5960
}
61+
/* ---------------------------------------------------------------- */
62+
63+
- (UIKeyboardAppearance) darkKeyboardAppearanceTemplateMethod {
64+
return UIKeyboardAppearanceDark;
65+
}
66+
67+
- (UIKeyboardAppearance) lightKeyboardAppearanceTemplateMethod {
68+
return UIKeyboardAppearanceLight;
69+
}
70+
71+
- (BOOL) styleDark {
72+
UIView *browserView = [self hackishlyFoundBrowserView];
73+
if (browserView == nil) {
74+
return false;
75+
}
76+
77+
Method m = class_getInstanceMethod( [self class], @selector( darkKeyboardAppearanceTemplateMethod ) );
78+
IMP imp = method_getImplementation( m );
79+
80+
Method m2 = class_getInstanceMethod( [browserView class], @selector(keyboardAppearance) );
81+
IMP imp2 = method_getImplementation( m2 );
82+
83+
return imp == imp2;
84+
}
6085

86+
- (void) setStyleDark:(BOOL)styleDark {
87+
UIView *browserView = [self hackishlyFoundBrowserView];
88+
if (browserView == nil) {
89+
return;
90+
}
91+
92+
if ( styleDark ) {
93+
Method m = class_getInstanceMethod( [self class], @selector( darkKeyboardAppearanceTemplateMethod ) );
94+
IMP imp = method_getImplementation( m );
95+
const char* typeEncoding = method_getTypeEncoding( m );
96+
class_replaceMethod( [browserView class], @selector(keyboardAppearance), imp, typeEncoding );
97+
}
98+
else {
99+
Method m = class_getInstanceMethod( [self class], @selector( lightKeyboardAppearanceTemplateMethod ) );
100+
IMP imp = method_getImplementation( m );
101+
const char* typeEncoding = method_getTypeEncoding( m );
102+
class_replaceMethod( [browserView class], @selector(keyboardAppearance), imp, typeEncoding );
103+
}
104+
}
105+
61106
@end
107+

www/keyboard.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Keyboard.disableScroll = function(disable) {
1818
exec(null, null, "Keyboard", "disableScroll", [disable]);
1919
};
2020

21+
Keyboard.styleDark = function(dark) {
22+
exec(null, null, "Keyboard", "styleDark", [dark]);
23+
};
24+
2125
Keyboard.isVisible = false;
2226

2327
module.exports = Keyboard;

0 commit comments

Comments
 (0)