22#import " UIWebViewAccessoryHiding.h"
33#import < Cordova/CDVAvailability.h>
44
5-
65@implementation IonicKeyboard
76
87@synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
8+ @synthesize disableScroll = _disableScroll;
99
1010- (void )pluginInitialize
1111{
12-
12+
1313 NSNotificationCenter * nc = [NSNotificationCenter defaultCenter ];
1414 __weak IonicKeyboard* weakSelf = self;
15+
16+ // set defaults
17+ weakSelf.hideKeyboardAccessoryBar = NO ;
18+ weakSelf.disableScroll = NO ;
1519
16- weakSelf.webView .scrollView .scrollEnabled = NO ;
17-
18- // Until disabling the auto-scroll in iOS 7 works
19- self.hideKeyboardAccessoryBar = YES ;
20+ weakSelf.webView .scrollView .delegate = self;
2021
2122 _keyboardShowObserver = [nc addObserverForName: UIKeyboardWillShowNotification
2223 object: nil
@@ -27,6 +28,7 @@ - (void)pluginInitialize
2728 keyboardFrame = [self .viewController.view convertRect: keyboardFrame fromView: nil ];
2829
2930 [weakSelf.commandDelegate evalJs: [NSString stringWithFormat: @" cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); " , [@(keyboardFrame.size.height) stringValue ]]];
31+
3032
3133 }];
3234
@@ -37,6 +39,27 @@ - (void)pluginInitialize
3739 [weakSelf.commandDelegate evalJs: @" cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.hidekeyboard'); " ];
3840 }];
3941}
42+ - (BOOL )disableScroll
43+ {
44+ return _disableScroll;
45+ }
46+
47+ - (void )setDisableScroll : (BOOL )disableScroll
48+ {
49+ __weak IonicKeyboard* weakSelf = self;
50+
51+ if (disableScroll == _disableScroll) {
52+ return ;
53+ }
54+ if (disableScroll){
55+ weakSelf.webView .scrollView .scrollEnabled = NO ;
56+ }
57+ else {
58+ weakSelf.webView .scrollView .scrollEnabled = YES ;
59+ }
60+
61+ _disableScroll = disableScroll;
62+ }
4063
4164
4265- (BOOL )hideKeyboardAccessoryBar
@@ -61,6 +84,14 @@ - (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar
6184 _hideKeyboardAccessoryBar = hideKeyboardAccessoryBar;
6285}
6386
87+
88+ /* ------------------------------------------------------------- */
89+
90+ - (void )scrollViewDidScroll : (UIScrollView *)scrollView
91+ {
92+ [scrollView setContentOffset: CGPointZero];
93+ }
94+
6495/* ------------------------------------------------------------- */
6596
6697- (void )dealloc
@@ -73,25 +104,29 @@ - (void)dealloc
73104
74105/* ------------------------------------------------------------- */
75106
76- /*
77- - (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command
107+ - (void ) disableScroll : (CDVInvokedUrlCommand*)command
78108{
109+ if (!command.arguments || ![command.arguments count ]){
110+ return ;
111+ }
79112 id value = [command.arguments objectAtIndex: 0 ];
80- if (!([value isKindOfClass:[NSNumber class]])) {
81- value = [NSNumber numberWithBool:NO];
113+
114+ self.disableScroll = [value boolValue ];
115+ }
116+
117+ - (void ) hideKeyboardAccessoryBar : (CDVInvokedUrlCommand*)command
118+ {
119+ if (!command.arguments || ![command.arguments count ]){
120+ return ;
82121 }
122+ id value = [command.arguments objectAtIndex: 0 ];
83123
84124 self.hideKeyboardAccessoryBar = [value boolValue ];
85125}
86- */
87126
88127- (void ) close : (CDVInvokedUrlCommand*)command
89128{
90129 [self .webView endEditing: YES ];
91130}
92131
93-
94132@end
95-
96-
97-
0 commit comments