2021-04-01 08:39:15 +02:00
|
|
|
//
|
|
|
|
// ProfilePagingViewController.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-29.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
import Pageboy
|
|
|
|
import Tabman
|
|
|
|
|
2021-05-08 05:03:34 +02:00
|
|
|
protocol ProfilePagingViewControllerDelegate: AnyObject {
|
2021-04-01 08:39:15 +02:00
|
|
|
func profilePagingViewController(_ viewController: ProfilePagingViewController, didScrollToPostCustomScrollViewContainerController customScrollViewContainerController: ScrollViewContainer, atIndex index: Int)
|
|
|
|
}
|
|
|
|
|
|
|
|
final class ProfilePagingViewController: TabmanViewController {
|
|
|
|
|
|
|
|
weak var pagingDelegate: ProfilePagingViewControllerDelegate?
|
|
|
|
var viewModel: ProfilePagingViewModel!
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - PageboyViewControllerDelegate
|
|
|
|
|
|
|
|
override func pageboyViewController(_ pageboyViewController: PageboyViewController, didScrollToPageAt index: TabmanViewController.PageIndex, direction: PageboyViewController.NavigationDirection, animated: Bool) {
|
|
|
|
super.pageboyViewController(pageboyViewController, didScrollToPageAt: index, direction: direction, animated: animated)
|
|
|
|
|
|
|
|
let viewController = viewModel.viewControllers[index]
|
2021-05-21 09:23:02 +02:00
|
|
|
(viewController as? StatusTableViewControllerNavigateable)?.overrideNavigationScrollPosition = .top
|
2021-04-01 08:39:15 +02:00
|
|
|
pagingDelegate?.profilePagingViewController(self, didScrollToPostCustomScrollViewContainerController: viewController, atIndex: index)
|
|
|
|
}
|
|
|
|
|
2021-05-21 09:23:02 +02:00
|
|
|
// make key commands works
|
|
|
|
override var canBecomeFirstResponder: Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-04-01 08:39:15 +02:00
|
|
|
deinit {
|
|
|
|
os_log("%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ProfilePagingViewController {
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
view.backgroundColor = .clear
|
|
|
|
dataSource = viewModel
|
|
|
|
}
|
2021-05-21 09:23:02 +02:00
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
|
|
|
becomeFirstResponder()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-04-01 08:39:15 +02:00
|
|
|
|
2021-05-21 11:18:03 +02:00
|
|
|
// workaround to fix tab man responder chain issue
|
2021-05-21 09:23:02 +02:00
|
|
|
extension ProfilePagingViewController {
|
2021-05-21 11:18:03 +02:00
|
|
|
|
2021-05-21 09:23:02 +02:00
|
|
|
override var keyCommands: [UIKeyCommand]? {
|
|
|
|
return currentViewController?.keyCommands
|
|
|
|
}
|
|
|
|
|
2021-05-21 11:18:03 +02:00
|
|
|
@objc func navigateKeyCommandHandlerRelay(_ sender: UIKeyCommand) {
|
|
|
|
(currentViewController as? StatusTableViewControllerNavigateable)?.navigateKeyCommandHandlerRelay(sender)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func statusKeyCommandHandlerRelay(_ sender: UIKeyCommand) {
|
2021-05-21 10:52:47 +02:00
|
|
|
(currentViewController as? StatusTableViewControllerNavigateable)?.statusKeyCommandHandlerRelay(sender)
|
2021-05-21 09:23:02 +02:00
|
|
|
}
|
|
|
|
|
2021-04-01 08:39:15 +02:00
|
|
|
}
|