Skip to content

iOS: Keyboard is not resized properly when resize mode is changed from native to none #2216

Open
@cornelius-behrend

Description

@cornelius-behrend

Bug Report

Plugin(s)

@capacitor/keyboard 6.0.2

Capacitor Version

@capacitor/cli: 6.1.2
@capacitor/android: 6.1.2
@capacitor/ios: 6.1.2
@capacitor/core: 6.1.2

Platform(s)

  • iOS

Current Behavior

When the keyboard is opened with the resize mode native and then the resize mode is switched to none while the keyboard is still open, closing the keyboard results in a black box since the web view is not reseted to its original bounds.

Expected Behavior

Even when changing the resize mode back and forth, the web view should be displayed correctly.

Code Reproduction

This can be i.e. fixed by adding a reset of the frame if the resize mode is "none".


- (void)_updateFrame
{
  CGRect f, wf = CGRectZero;
  UIWindow * window = nil;
    
  if ([[[UIApplication sharedApplication] delegate] respondsToSelector:@selector(window)]) {
    window = [[[UIApplication sharedApplication] delegate] window];
  }
  
  if (!window) {
    if (@available(iOS 13.0, *)) {
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", UIWindowScene.class];
      UIScene *scene = [UIApplication.sharedApplication.connectedScenes.allObjects filteredArrayUsingPredicate:predicate].firstObject;
      window = [[(UIWindowScene*)scene windows] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"isKeyWindow == YES"]].firstObject;
    }
  }
  if (window) {
    f = [window bounds];
  }
  if (self.webView != nil) {
    wf = self.webView.frame;
  }
  switch (self.keyboardResizes) {
    case ResizeBody:
    {
      [self resizeElement:@"document.body" withPaddingBottom:_paddingBottom withScreenHeight:(int)f.size.height];
      break;
    }
    case ResizeIonic:
    {
      [self resizeElement:@"document.querySelector('ion-app')" withPaddingBottom:_paddingBottom withScreenHeight:(int)f.size.height];
      break;
    }
    case ResizeNative:
    {
      [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;
    }
    case ResizeNone:
    {
      [self.webView setFrame:CGRectMake(wf.origin.x, wf.origin.y, f.size.width - wf.origin.x, f.size.height - wf.origin.y)];
      break;
    }
    default:
      break;
  }
  [self resetScrollView];
}

Other Technical Details

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions