RxKeyboard icon indicating copy to clipboard operation
RxKeyboard copied to clipboard

The visibleHeight's output is wrong when 'Reduce Motion' and 'Prefer Cross-Fade Transitions' are on.

Open yongseongkim opened this issue 3 years ago • 4 comments

First, turn on 'ReduceMotion' and 'Prefer Cross-FadeTransitions'. (Settings > Accessibility > Motion > ReduceMotion and Prefer Cross-Fade Transitions) And make a view controller containing UITableView like below.

import UIKit
import SnapKit
import RxKeyboard
import RxSwift

class TableViewCell: UITableViewCell {
}

class ViewController: UIViewController {

    private let textField = UITextField()
    private let tableView = UITableView()
    private let disposeBag = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()
        initialize()

        RxKeyboard.instance.frame
            .drive(onNext: { frame in
                print("## frame \(frame)")
                // Result when the keyboard appeared: ## frame (0.0, 521.0, 375.0, 291.0)
                // Result when the keyboard disappeared: ## frame (0.0, 812.0, 375.0, 71.0)
            })
            .disposed(by: disposeBag)

        RxKeyboard.instance.visibleHeight
            .drive(onNext: { frame in
                print("## visibleHeight \(frame)")
                // Result when the keyboard appeared: ## visibleHeight 291.0
                // Result when the keyboard disappeared: ## visibleHeight 0.0 and -71.0 (print twice)
            })
            .disposed(by: disposeBag)
    }

    private func initialize() {
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(TableViewCell.self, forCellReuseIdentifier: "TableViewCell")
        tableView.keyboardDismissMode = .onDrag
        view.addSubview(textField)
        view.addSubview(tableView)

        textField.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(50)
            make.leading.trailing.equalToSuperview().inset(25)
            make.height.equalTo(50)
        }
        tableView.snp.makeConstraints { make in
            make.top.equalTo(textField.snp.bottom)
            make.leading.bottom.trailing.equalToSuperview()
        }
    }
}

The RxKeyboard.frame output is (0.0, 812.0, 375.0, 291.0) when the keyboard is visible. But after the keyboard dismiss, the RxKeyboard.frame is (0.0, 812.0, 375.0, 71.0) So RxKeyboard.visibleHeight returns -71. I use the CGRect.intersection function instead of subtracting origin.y for calculating visible height.

yongseongkim avatar May 24 '21 15:05 yongseongkim

Please review this PR. T.T

yongseongkim avatar May 06 '22 01:05 yongseongkim

I have the same issue too

vberezkin avatar May 10 '22 16:05 vberezkin

can we merge and release new version please?

pablocryptocom avatar May 18 '22 21:05 pablocryptocom

@Loupehope Any update ?

techinpark avatar Jul 10 '22 10:07 techinpark

@Loupehope Thanks for that fix! Sorry for delay. I am passing by and noticed your PR.

bigMOTOR avatar Apr 11 '23 09:04 bigMOTOR

Thanks a lot for contributing @yongseongkim! I've invited you to join the RxSwiftCommunity GitHub organization – no pressure to accept! If you'd like more information on what this means, check out our contributor guidelines and feel free to reach out with any questions.

Generated by :no_entry_sign: dangerJS

rxswiftcommunity[bot] avatar Apr 11 '23 09:04 rxswiftcommunity[bot]