RxSwiftCommunity / RxKeyboard

Reactive Keyboard in iOS
MIT License
1.6k stars 175 forks source link

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

Closed yongseongkim closed 1 year ago

yongseongkim commented 3 years ago

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 commented 2 years ago

Please review this PR. T.T

vberezkin commented 2 years ago

I have the same issue too

pablocryptocom commented 2 years ago

can we merge and release new version please?

techinpark commented 2 years ago

@Loupehope Any update ?

bigMOTOR commented 1 year ago

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

rxswiftcommunity[bot] commented 1 year ago

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