Skip to content

Commit

Permalink
Improve ContainerViewController code
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Jan 11, 2024
1 parent 66585bb commit 1758c9e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Zotero/Scenes/General/Views/ContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ContainerViewController: UIViewController {
.observe(on: MainScheduler.instance)
.subscribe(onNext: { [weak self] notification in
guard let self, let data = notification.keyboardData else { return }
moveToKeyboard(data, willShow: true)
moveToKeyboard(self, data, willShow: true)
})
.disposed(by: disposeBag)

Expand All @@ -108,9 +108,21 @@ class ContainerViewController: UIViewController {
.observe(on: MainScheduler.instance)
.subscribe(onNext: { [weak self] notification in
guard let self, let data = notification.keyboardData else { return }
moveToKeyboard(data, willShow: false)
moveToKeyboard(self, data, willShow: false)
})
.disposed(by: disposeBag)

func moveToKeyboard(_ self: ContainerViewController, _ data: KeyboardData, willShow: Bool) {
guard let containerCenterY = self.containerCenterY else { return }

containerCenterY.constant = willShow ? data.endFrame.height / 2 : 0

guard self.isViewLoaded else { return }

UIView.animate(withDuration: 0.2) {
self.view.layoutIfNeeded()
}
}
}
}

Expand Down Expand Up @@ -148,16 +160,4 @@ class ContainerViewController: UIViewController {
@objc private func hide() {
presentingViewController?.dismiss(animated: true, completion: nil)
}

private func moveToKeyboard(_ data: KeyboardData, willShow: Bool) {
guard let containerCenterY else { return }

containerCenterY.constant = willShow ? data.endFrame.height / 2 : 0

guard isViewLoaded else { return }

UIView.animate(withDuration: 0.2) {
self.view.layoutIfNeeded()
}
}
}

0 comments on commit 1758c9e

Please sign in to comment.