feat: make notification coordinator works

This commit is contained in:
CMK 2021-10-29 18:56:58 +08:00
parent 2f0b321fd9
commit e669d17d49
3 changed files with 62 additions and 58 deletions

View File

@ -90,45 +90,44 @@ final public class SceneCoordinator {
// Delay in next run loop // Delay in next run loop
// DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
// guard let self = self else { return } guard let self = self else { return }
//
// // Note: // Note:
// // show (push) on phone or pad (compact) // show (push) on phone and pad
// // showDetail in .secondary in UISplitViewController on pad (expand) let from: UIViewController? = {
// let from: UIViewController? = { if let splitViewController = self.splitViewController {
// if let splitViewController = self.splitViewController { if splitViewController.compactMainTabBarViewController.topMost?.view.window != nil {
// if splitViewController.mainTabBarController.topMost?.view.window != nil { // compact
// // compact return splitViewController.compactMainTabBarViewController.topMost
// return splitViewController.mainTabBarController.topMost } else {
// } else { // expand
// // expand return splitViewController.contentSplitViewController.mainTabBarController.topMost
// return splitViewController.viewController(for: .supplementary) }
// } } else {
// } else { return self.tabBarController.topMost
// return self.tabBarController.topMost }
// } }()
// }()
// // show notification related content
// // show notification related content guard let type = Mastodon.Entity.Notification.NotificationType(rawValue: pushNotification.notificationType) else { return }
// guard let type = Mastodon.Entity.Notification.NotificationType(rawValue: pushNotification.notificationType) else { return } let notificationID = String(pushNotification.notificationID)
// let notificationID = String(pushNotification.notificationID)
// switch type {
// switch type { case .follow:
// case .follow: let profileViewModel = RemoteProfileViewModel(context: appContext, notificationID: notificationID)
// let profileViewModel = RemoteProfileViewModel(context: appContext, notificationID: notificationID) self.present(scene: .profile(viewModel: profileViewModel), from: from, transition: .show)
// self.present(scene: .profile(viewModel: profileViewModel), from: from, transition: .show) case .followRequest:
// case .followRequest: // do nothing
// // do nothing break
// break case .mention, .reblog, .favourite, .poll, .status:
// case .mention, .reblog, .favourite, .poll, .status: let threadViewModel = RemoteThreadViewModel(context: appContext, notificationID: notificationID)
// let threadViewModel = RemoteThreadViewModel(context: appContext, notificationID: notificationID) self.present(scene: .thread(viewModel: threadViewModel), from: from, transition: .show)
// self.present(scene: .thread(viewModel: threadViewModel), from: from, transition: .show) case ._other:
// case ._other: assertionFailure()
// assertionFailure() break
// break }
// } } // end DispatchQueue.main.async
// } // end DispatchQueue.main.async
} }
.store(in: &disposeBag) .store(in: &disposeBag)
} }
@ -283,18 +282,6 @@ extension SceneCoordinator {
switch transition { switch transition {
case .show: case .show:
// if let splitViewController = splitViewController, !splitViewController.isCollapsed,
// let supplementaryViewController = splitViewController.viewController(for: .supplementary) as? UINavigationController,
// (supplementaryViewController === presentingViewController || supplementaryViewController.viewControllers.contains(presentingViewController)) ||
// (presentingViewController is UserTimelineViewController && presentingViewController.view.isDescendant(of: supplementaryViewController.view))
// {
// fallthrough
// } else {
// if secondaryStackHashValues.contains(presentingViewController.hashValue) {
// secondaryStackHashValues.insert(viewController.hashValue)
// }
// presentingViewController.show(viewController, sender: sender)
// }
presentingViewController.show(viewController, sender: sender) presentingViewController.show(viewController, sender: sender)
case .showDetail: case .showDetail:
secondaryStackHashValues.insert(viewController.hashValue) secondaryStackHashValues.insert(viewController.hashValue)
@ -362,6 +349,11 @@ extension SceneCoordinator {
} }
func switchToTabBar(tab: MainTabBarController.Tab) { func switchToTabBar(tab: MainTabBarController.Tab) {
splitViewController?.contentSplitViewController.currentSupplementaryTab = tab
splitViewController?.compactMainTabBarViewController.selectedIndex = tab.rawValue
splitViewController?.compactMainTabBarViewController.currentTab.value = tab
tabBarController.selectedIndex = tab.rawValue tabBarController.selectedIndex = tab.rawValue
tabBarController.currentTab.value = tab tabBarController.currentTab.value = tab
} }

View File

@ -44,10 +44,11 @@ final class ProfileHeaderViewController: UIViewController {
let profileHeaderView = ProfileHeaderView() let profileHeaderView = ProfileHeaderView()
let pageSegmentedControl: UISegmentedControl = { let pageSegmentedControl: UISegmentedControl = {
let segmenetedControl = UISegmentedControl(items: ["A", "B"]) let segmentedControl = UISegmentedControl(items: ["A", "B"])
segmenetedControl.selectedSegmentIndex = 0 segmentedControl.selectedSegmentIndex = 0
return segmenetedControl return segmentedControl
}() }()
var pageSegmentedControlLeadingLayoutConstraint: NSLayoutConstraint!
private var isBannerPinned = false private var isBannerPinned = false
private var bottomShadowAlpha: CGFloat = 0.0 private var bottomShadowAlpha: CGFloat = 0.0
@ -118,9 +119,10 @@ extension ProfileHeaderViewController {
pageSegmentedControl.translatesAutoresizingMaskIntoConstraints = false pageSegmentedControl.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(pageSegmentedControl) view.addSubview(pageSegmentedControl)
pageSegmentedControlLeadingLayoutConstraint = pageSegmentedControl.leadingAnchor.constraint(equalTo: view.leadingAnchor)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
pageSegmentedControl.topAnchor.constraint(equalTo: profileHeaderView.bottomAnchor, constant: ProfileHeaderViewController.segmentedControlMarginHeight), pageSegmentedControl.topAnchor.constraint(equalTo: profileHeaderView.bottomAnchor, constant: ProfileHeaderViewController.segmentedControlMarginHeight),
pageSegmentedControl.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor), pageSegmentedControlLeadingLayoutConstraint, // Fix iPad layout issue
pageSegmentedControl.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor), pageSegmentedControl.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
view.bottomAnchor.constraint(equalTo: pageSegmentedControl.bottomAnchor, constant: ProfileHeaderViewController.segmentedControlMarginHeight), view.bottomAnchor.constraint(equalTo: pageSegmentedControl.bottomAnchor, constant: ProfileHeaderViewController.segmentedControlMarginHeight),
pageSegmentedControl.heightAnchor.constraint(equalToConstant: ProfileHeaderViewController.segmentedControlHeight).priority(.defaultHigh), pageSegmentedControl.heightAnchor.constraint(equalToConstant: ProfileHeaderViewController.segmentedControlHeight).priority(.defaultHigh),
@ -133,10 +135,10 @@ extension ProfileHeaderViewController {
viewModel.isTitleViewContentOffsetSet.eraseToAnyPublisher() viewModel.isTitleViewContentOffsetSet.eraseToAnyPublisher()
) )
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak self] viewDidAppear, isTitleViewContentOffsetDidSetted in .sink { [weak self] viewDidAppear, isTitleViewContentOffsetDidSet in
guard let self = self else { return } guard let self = self else { return }
self.titleView.titleLabel.alpha = viewDidAppear && isTitleViewContentOffsetDidSetted ? 1 : 0 self.titleView.titleLabel.alpha = viewDidAppear && isTitleViewContentOffsetDidSet ? 1 : 0
self.titleView.subtitleLabel.alpha = viewDidAppear && isTitleViewContentOffsetDidSetted ? 1 : 0 self.titleView.subtitleLabel.alpha = viewDidAppear && isTitleViewContentOffsetDidSet ? 1 : 0
} }
.store(in: &disposeBag) .store(in: &disposeBag)
@ -283,6 +285,13 @@ extension ProfileHeaderViewController {
setupBottomShadow() setupBottomShadow()
} }
override func viewLayoutMarginsDidChange() {
super.viewLayoutMarginsDidChange()
let margin = view.frame.maxX - view.readableContentGuide.layoutFrame.maxX
pageSegmentedControlLeadingLayoutConstraint.constant = margin
}
} }
extension ProfileHeaderViewController { extension ProfileHeaderViewController {

View File

@ -517,6 +517,7 @@ extension ProfileViewController {
.assign(to: \.value, on: profileHeaderViewController.viewModel.displayProfileInfo.note) .assign(to: \.value, on: profileHeaderViewController.viewModel.displayProfileInfo.note)
.store(in: &disposeBag) .store(in: &disposeBag)
viewModel.statusesCount viewModel.statusesCount
.receive(on: DispatchQueue.main)
.sink { [weak self] count in .sink { [weak self] count in
guard let self = self else { return } guard let self = self else { return }
let text = count.flatMap { MastodonMetricFormatter().string(from: $0) } ?? "-" let text = count.flatMap { MastodonMetricFormatter().string(from: $0) } ?? "-"
@ -526,6 +527,7 @@ extension ProfileViewController {
} }
.store(in: &disposeBag) .store(in: &disposeBag)
viewModel.followingCount viewModel.followingCount
.receive(on: DispatchQueue.main)
.sink { [weak self] count in .sink { [weak self] count in
guard let self = self else { return } guard let self = self else { return }
let text = count.flatMap { MastodonMetricFormatter().string(from: $0) } ?? "-" let text = count.flatMap { MastodonMetricFormatter().string(from: $0) } ?? "-"
@ -535,6 +537,7 @@ extension ProfileViewController {
} }
.store(in: &disposeBag) .store(in: &disposeBag)
viewModel.followersCount viewModel.followersCount
.receive(on: DispatchQueue.main)
.sink { [weak self] count in .sink { [weak self] count in
guard let self = self else { return } guard let self = self else { return }
let text = count.flatMap { MastodonMetricFormatter().string(from: $0) } ?? "-" let text = count.flatMap { MastodonMetricFormatter().string(from: $0) } ?? "-"