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

Commit d1f66f2

Browse files
committed
iOS updates
1 parent 8007e89 commit d1f66f2

File tree

3 files changed

+56
-44
lines changed

3 files changed

+56
-44
lines changed

src/ios/IonicKeyboard.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#import <Cordova/CDVPlugin.h>
22

3-
@interface IonicKeyboard : CDVPlugin {
3+
@interface IonicKeyboard : CDVPlugin <UIScrollViewDelegate> {
44
@protected
55
id _keyboardShowObserver, _keyboardHideObserver;
66
}
77

88
@property (readwrite, assign, getter = hideKeyboardAccessoryBar, setter = setHideKeyboardAccessoryBar:) BOOL hideKeyboardAccessoryBar;
9-
@property (readwrite, assign) BOOL keyboardIsVisible;
9+
@property (readwrite, assign) BOOL disableScroll;
1010

11-
//- (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command;
11+
- (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command;
1212
- (void) close:(CDVInvokedUrlCommand*)command;
1313

1414
@end
15+

src/ios/IonicKeyboard.m

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
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-

www/keyboard.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
/*
2-
*
3-
* Licensed to the Apache Software Foundation (ASF) under one
4-
* or more contributor license agreements. See the NOTICE file
5-
* distributed with this work for additional information
6-
* regarding copyright ownership. The ASF licenses this file
7-
* to you under the Apache License, Version 2.0 (the
8-
* "License"); you may not use this file except in compliance
9-
* with the License. You may obtain a copy of the License at
10-
*
11-
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
13-
* Unless required by applicable law or agreed to in writing,
14-
* software distributed under the License is distributed on an
15-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16-
* KIND, either express or implied. See the License for the
17-
* specific language governing permissions and limitations
18-
* under the License.
19-
*
20-
*/
211

222
var argscheck = require('cordova/argscheck'),
233
utils = require('cordova/utils'),
@@ -26,10 +6,6 @@ var argscheck = require('cordova/argscheck'),
266
var Keyboard = function() {
277
};
288

29-
Keyboard.resizeView = function(offset) {
30-
exec(null, null, "Keyboard", "resizeView", [offset]);
31-
};
32-
339
Keyboard.hideKeyboardAccessoryBar = function(hide) {
3410
exec(null, null, "Keyboard", "hideKeyboardAccessoryBar", [hide]);
3511
};
@@ -38,8 +14,8 @@ Keyboard.close = function() {
3814
exec(null, null, "Keyboard", "close", []);
3915
};
4016

41-
Keyboard.disableScroll = function() {
42-
exec(null, null, "Keyboard", "disableScroll", []);
17+
Keyboard.disableScroll = function(disable) {
18+
exec(null, null, "Keyboard", "disableScroll", [disable]);
4319
};
4420

4521
Keyboard.isVisible = false;

0 commit comments

Comments
 (0)