Skip to content

Commit 350f256

Browse files
authored
Merge pull request cjpearson#21 from sfaizanh/patch-1
fix(padding) Incorrect height of Webview
2 parents db0d327 + b78370e commit 350f256

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/ios/CDVIonicKeyboard.m

+19-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ - (void)pluginInitialize
5555
{
5656
NSDictionary *settings = self.commandDelegate.settings;
5757

58+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarDidChangeFrame:) name: UIApplicationDidChangeStatusBarFrameNotification object:nil];
59+
5860
self.keyboardResizes = ResizeNative;
5961
BOOL doesResize = [settings cordovaBoolSettingForKey:@"KeyboardResize" defaultValue:YES];
6062
if (!doesResize) {
@@ -95,6 +97,11 @@ - (void)pluginInitialize
9597
}
9698
}
9799

100+
-(void)statusBarDidChangeFrame:(NSNotification*)notification
101+
{
102+
[self _updateFrame];
103+
}
104+
98105

99106
#pragma mark Keyboard events
100107

@@ -174,26 +181,35 @@ - (void)setPaddingBottom:(int)paddingBottom delay:(NSTimeInterval)delay
174181

175182
- (void)_updateFrame
176183
{
184+
CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
185+
int statusBarHeight = MIN(statusBarSize.width, statusBarSize.height);
186+
187+
int _paddingBottom = (int)self.paddingBottom;
188+
189+
if (statusBarHeight == 40) {
190+
_paddingBottom = _paddingBottom + 20;
191+
}
177192
NSLog(@"CDVIonicKeyboard: updating frame");
178193
CGRect f = [[UIScreen mainScreen] bounds];
194+
CGRect wf = self.webView.frame;
179195
switch (self.keyboardResizes) {
180196
case ResizeBody:
181197
{
182198
NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, document.body);",
183-
(int)self.paddingBottom, (int)f.size.height];
199+
_paddingBottom, (int)f.size.height];
184200
[self.commandDelegate evalJs:js];
185201
break;
186202
}
187203
case ResizeIonic:
188204
{
189205
NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, document.querySelector('ion-app'));",
190-
(int)self.paddingBottom, (int)f.size.height];
206+
_paddingBottom, (int)f.size.height];
191207
[self.commandDelegate evalJs:js];
192208
break;
193209
}
194210
case ResizeNative:
195211
{
196-
[self.webView setFrame:CGRectMake(f.origin.x, f.origin.y, f.size.width, f.size.height - self.paddingBottom)];
212+
[self.webView setFrame:CGRectMake(wf.origin.x, wf.origin.y, f.size.width - wf.origin.x, f.size.height - wf.origin.y - self.paddingBottom)];
197213
break;
198214
}
199215
default:

0 commit comments

Comments
 (0)