Skip to content

Commit aa3d007

Browse files
author
Andrew(유금상)
committed
Example support iPhone X
1 parent 8b18390 commit aa3d007

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

Example/Sources/ViewControllers/MessageListViewController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ class MessageListViewController: UIViewController {
9292
RxKeyboard.instance.visibleHeight
9393
.drive(onNext: { [weak self] keyboardVisibleHeight in
9494
guard let `self` = self, self.didSetupViewConstraints else { return }
95+
var actualKeyboardHeight = keyboardVisibleHeight
96+
if #available(iOS 11.0, *), keyboardVisibleHeight > 0 {
97+
actualKeyboardHeight = actualKeyboardHeight - self.view.safeAreaInsets.bottom
98+
}
99+
95100
self.messageInputBar.snp.updateConstraints { make in
96-
make.bottom.equalTo(self.bottomLayoutGuide.snp.top).offset(-keyboardVisibleHeight)
101+
make.bottom.equalTo(self.bottomLayoutGuide.snp.top).offset(-actualKeyboardHeight)
97102
}
98103
self.view.setNeedsLayout()
99104
UIView.animate(withDuration: 0) {

Example/Sources/Views/MessageInputBar.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import UIKit
1010

1111
import RxCocoa
1212
import RxSwift
13+
import RxKeyboard
1314

1415
final class MessageInputBar: UIView {
1516

@@ -63,8 +64,40 @@ final class MessageInputBar: UIView {
6364
.map { text in text?.isEmpty == false }
6465
.bind(to: self.sendButton.rx.isEnabled)
6566
.disposed(by: self.disposeBag)
67+
68+
RxKeyboard.instance.visibleHeight
69+
.map { $0 > 0 }
70+
.distinctUntilChanged().drive(onNext: { [weak self] (visible) in
71+
guard let `self` = self else {
72+
return
73+
}
74+
75+
var bottomMargin = 0.f
76+
if #available(iOS 11.0, *), !visible, let bottomInset = self.superview?.safeAreaInsets.bottom {
77+
bottomMargin = bottomInset
78+
}
79+
80+
self.toolbar.snp.remakeConstraints({ (make) in
81+
make.left.right.top.equalTo(0)
82+
make.bottom.equalTo(bottomMargin)
83+
})
84+
})
85+
.disposed(by: self.disposeBag)
6686
}
67-
87+
88+
@available(iOS 11.0, *)
89+
override func safeAreaInsetsDidChange() {
90+
super.safeAreaInsetsDidChange()
91+
guard let bottomInset = self.superview?.safeAreaInsets.bottom else {
92+
return
93+
}
94+
95+
self.toolbar.snp.remakeConstraints { make in
96+
make.top.left.right.equalTo(0)
97+
make.bottom.equalTo(bottomInset)
98+
}
99+
}
100+
68101
required init?(coder aDecoder: NSCoder) {
69102
fatalError("init(coder:) has not been implemented")
70103
}

0 commit comments

Comments
 (0)