Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug on iPhone X #84

Open
AlexisQapa opened this issue Dec 26, 2018 · 6 comments
Open

Bug on iPhone X #84

AlexisQapa opened this issue Dec 26, 2018 · 6 comments

Comments

@AlexisQapa
Copy link

Hello,

On iPhone X, Xr, Xs in the example when you tap the search bar and the keyboard appear there is a gap between the bar and the keyboard. The reason is because it's constrained to the safe area in MessageListViewController (96) :
if #available(iOS 11.0, *) {
make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom).offset(-keyboardVisibleHeight)
} else {
make.bottom.equalTo(self.bottomLayoutGuide.snp.top).offset(-keyboardVisibleHeight)
}

While this is intended behaviour when there is no keyboard this doesn't work when it open. I'm gonna try to fix it but if someone as a nice way to do it it would be great to have it in the example.

@cfr
Copy link

cfr commented Mar 14, 2019

Hey, not sure it is related: I'm also experience this bug on X with google keyboard. It is reporting wrong visibleHeight on new devices or OS, though It seems RxKeyboard.instance.frame is OK.

@pauloec
Copy link

pauloec commented Jul 16, 2019

Having the same issue. Not sure if someone tested with iPhone X models. safeAreaInsets are not taken into account and when using visibleHeight it is 0 because it hasn't been drawn yet.

@yojkim
Copy link

yojkim commented Sep 10, 2019

Same issue on me.
Third-party keyboards return wrong visibleHeight value 🤔

@shingo-nakanishi
Copy link

shingo-nakanishi commented Sep 13, 2019

Same issue on my project without SnapKit.

I solved it as follows.

@IBOutlet weak var bottomConstraint: NSLayoutConstraint!

and

RxKeyboard.instance.visibleHeight.drive(onNext: { [weak self] visibleHeight in
    guard let weakSelf = self else {
        return
    }

    if #available(iOS 11.0, *) {
        if visibleHeight == 0 {
            weakSelf.bottomConstraint.constant = 0
        } else {
            let height = visibleHeight - weakSelf.view.safeAreaInsets.bottom
            weakSelf.bottomConstraint.constant = -1 * height
        }
    } else {
        weakSelf.bottomConstraint.constant = -1 * visibleHeight
    }

    weakSelf.view.setNeedsLayout()
    weakSelf.view.layoutIfNeeded()
}).disposed(by: disposeBag)

Reference
https://stackoverflow.com/questions/46420488/iphonex-and-iphone-8-keyboard-height-are-different

@jinuman
Copy link

jinuman commented Apr 18, 2020

Same issue on me as well.

@IBOutlet weak var bottomConstraint: NSLayoutConstraint!

I am wondering where this constraint is hanging. @shingo-nakanishi Could you answer me?

@James-Geng
Copy link

James-Geng commented Jan 4, 2022

I solved as follows.

RxKeyboard.instance.visibleHeight
      .drive(onNext: { [weak self] keyboardVisibleHeight in
        guard let `self` = self, self.didSetupViewConstraints else { return }
        self.messageInputBar.snp.remakeConstraints { make in
            make.left.right.equalTo(0)
          if #available(iOS 11.0, *) {
              if keyboardVisibleHeight == 0 {
                  make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom).offset(-keyboardVisibleHeight)
              }
              else {
                  make.bottom.equalTo(self.view.snp.bottom).offset(-keyboardVisibleHeight)
              }
            
          } else {
            make.bottom.equalTo(self.bottomLayoutGuide.snp.top).offset(-keyboardVisibleHeight)
          }
        }
        self.view.setNeedsLayout()
        UIView.animate(withDuration: 0) {
          self.collectionView.contentInset.bottom = keyboardVisibleHeight + self.messageInputBar.height
          self.collectionView.scrollIndicatorInsets.bottom = self.collectionView.contentInset.bottom
          self.view.layoutIfNeeded()
        }
      })
      .disposed(by: self.disposeBag)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants