RxKeyboard icon indicating copy to clipboard operation
RxKeyboard copied to clipboard

Bug on iPhone X

Open AlexisQapa opened this issue 6 years ago • 6 comments

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.

AlexisQapa avatar Dec 26 '18 09:12 AlexisQapa

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.

cfr avatar Mar 14 '19 06:03 cfr

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.

pauloec avatar Jul 16 '19 10:07 pauloec

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

yojkim avatar Sep 10 '19 01:09 yojkim

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

shingo-nakanishi avatar Sep 13 '19 02:09 shingo-nakanishi

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?

jinuman avatar Apr 18 '20 15:04 jinuman

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)

James-Geng avatar Jan 04 '22 05:01 James-Geng