feat: scroll to top when select current segment in notification scene
This commit is contained in:
parent
4bee550f83
commit
f36bcf25ec
|
@ -18,6 +18,8 @@ final class NotificationViewController: UIViewController, NeedsDependency {
|
||||||
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
||||||
|
|
||||||
var disposeBag = Set<AnyCancellable>()
|
var disposeBag = Set<AnyCancellable>()
|
||||||
|
var observations = Set<NSKeyValueObservation>()
|
||||||
|
|
||||||
private(set) lazy var viewModel = NotificationViewModel(context: context)
|
private(set) lazy var viewModel = NotificationViewModel(context: context)
|
||||||
|
|
||||||
let segmentControl: UISegmentedControl = {
|
let segmentControl: UISegmentedControl = {
|
||||||
|
@ -119,6 +121,15 @@ extension NotificationViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
|
|
||||||
|
segmentControl.observe(\.selectedSegmentIndex, options: [.new]) { [weak self] segmentControl, _ in
|
||||||
|
guard let self = self else { return }
|
||||||
|
// scroll to top when select same segment
|
||||||
|
if segmentControl.selectedSegmentIndex == self.viewModel.selectedIndex.value.rawValue {
|
||||||
|
self.scrollToTop(animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.store(in: &observations)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
|
Loading…
Reference in New Issue