From f36bcf25ec5e2e6ca1704e8d4cf1cc6b5cf4d1f5 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 22 Jun 2021 19:58:20 +0800 Subject: [PATCH] feat: scroll to top when select current segment in notification scene --- .../Notification/NotificationViewController.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Mastodon/Scene/Notification/NotificationViewController.swift b/Mastodon/Scene/Notification/NotificationViewController.swift index 4ed5b5208..322f804af 100644 --- a/Mastodon/Scene/Notification/NotificationViewController.swift +++ b/Mastodon/Scene/Notification/NotificationViewController.swift @@ -18,6 +18,8 @@ final class NotificationViewController: UIViewController, NeedsDependency { weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } } var disposeBag = Set() + var observations = Set() + private(set) lazy var viewModel = NotificationViewModel(context: context) let segmentControl: UISegmentedControl = { @@ -119,6 +121,15 @@ extension NotificationViewController { } } .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) {