Skip to content

Commit

Permalink
Merge pull request cjpearson#21 from sfaizanh/patch-1
Browse files Browse the repository at this point in the history
fix(padding) Incorrect height of Webview
  • Loading branch information
mlynch authored May 24, 2018
2 parents db0d327 + b78370e commit 350f256
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/ios/CDVIonicKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ - (void)pluginInitialize
{
NSDictionary *settings = self.commandDelegate.settings;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarDidChangeFrame:) name: UIApplicationDidChangeStatusBarFrameNotification object:nil];

self.keyboardResizes = ResizeNative;
BOOL doesResize = [settings cordovaBoolSettingForKey:@"KeyboardResize" defaultValue:YES];
if (!doesResize) {
Expand Down Expand Up @@ -95,6 +97,11 @@ - (void)pluginInitialize
}
}

-(void)statusBarDidChangeFrame:(NSNotification*)notification
{
[self _updateFrame];
}


#pragma mark Keyboard events

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

- (void)_updateFrame
{
CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
int statusBarHeight = MIN(statusBarSize.width, statusBarSize.height);

int _paddingBottom = (int)self.paddingBottom;

if (statusBarHeight == 40) {
_paddingBottom = _paddingBottom + 20;
}
NSLog(@"CDVIonicKeyboard: updating frame");
CGRect f = [[UIScreen mainScreen] bounds];
CGRect wf = self.webView.frame;
switch (self.keyboardResizes) {
case ResizeBody:
{
NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, document.body);",
(int)self.paddingBottom, (int)f.size.height];
_paddingBottom, (int)f.size.height];
[self.commandDelegate evalJs:js];
break;
}
case ResizeIonic:
{
NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, document.querySelector('ion-app'));",
(int)self.paddingBottom, (int)f.size.height];
_paddingBottom, (int)f.size.height];
[self.commandDelegate evalJs:js];
break;
}
case ResizeNative:
{
[self.webView setFrame:CGRectMake(f.origin.x, f.origin.y, f.size.width, f.size.height - self.paddingBottom)];
[self.webView setFrame:CGRectMake(wf.origin.x, wf.origin.y, f.size.width - wf.origin.x, f.size.height - wf.origin.y - self.paddingBottom)];
break;
}
default:
Expand Down

0 comments on commit 350f256

Please sign in to comment.