refactor: To pass the ViewModel to coordinator
This commit is contained in:
parent
1411bcadf6
commit
21264fead1
@ -65,8 +65,8 @@ extension SceneCoordinator {
|
|||||||
case safari(url: URL)
|
case safari(url: URL)
|
||||||
case alertController(alertController: UIAlertController)
|
case alertController(alertController: UIAlertController)
|
||||||
case activityViewController(activityViewController: UIActivityViewController, sourceView: UIView?, barButtonItem: UIBarButtonItem?)
|
case activityViewController(activityViewController: UIActivityViewController, sourceView: UIView?, barButtonItem: UIBarButtonItem?)
|
||||||
case settings
|
case settings(viewModel: SettingsViewModel)
|
||||||
case report(userId: String, statusId: String?)
|
case report(viewModel: ReportViewModel)
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
case publicTimeline
|
case publicTimeline
|
||||||
#endif
|
#endif
|
||||||
@ -265,22 +265,13 @@ private extension SceneCoordinator {
|
|||||||
activityViewController.popoverPresentationController?.sourceView = sourceView
|
activityViewController.popoverPresentationController?.sourceView = sourceView
|
||||||
activityViewController.popoverPresentationController?.barButtonItem = barButtonItem
|
activityViewController.popoverPresentationController?.barButtonItem = barButtonItem
|
||||||
viewController = activityViewController
|
viewController = activityViewController
|
||||||
case .settings:
|
case .settings(let viewModel):
|
||||||
let _viewController = SettingsViewController()
|
let _viewController = SettingsViewController()
|
||||||
_viewController.viewModel = SettingsViewModel(context: appContext, coordinator: self)
|
_viewController.viewModel = viewModel
|
||||||
viewController = _viewController
|
viewController = _viewController
|
||||||
case .report(let userId, let statusId):
|
case .report(let viewModel):
|
||||||
guard let authenticationBox = appContext.authenticationService.activeMastodonAuthenticationBox.value else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
let _viewController = ReportViewController()
|
let _viewController = ReportViewController()
|
||||||
_viewController.viewModel = ReportViewModel(
|
_viewController.viewModel = viewModel
|
||||||
context: appContext,
|
|
||||||
coordinator: self,
|
|
||||||
domain: authenticationBox.domain,
|
|
||||||
userId: userId,
|
|
||||||
statusId: statusId
|
|
||||||
)
|
|
||||||
viewController = _viewController
|
viewController = _viewController
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
case .publicTimeline:
|
case .publicTimeline:
|
||||||
|
@ -332,7 +332,12 @@ extension HomeTimelineViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc private func showSettings(_ sender: UIAction) {
|
@objc private func showSettings(_ sender: UIAction) {
|
||||||
coordinator.present(scene: .settings, from: self, transition: .modal(animated: true, completion: nil))
|
let viewModel = SettingsViewModel(context: context)
|
||||||
|
coordinator.present(
|
||||||
|
scene: .settings(viewModel: viewModel),
|
||||||
|
from: self,
|
||||||
|
transition: .modal(animated: true, completion: nil)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func showReportAction(_ sender: UIAction) {
|
@objc private func showReportAction(_ sender: UIAction) {
|
||||||
@ -350,12 +355,20 @@ extension HomeTimelineViewController {
|
|||||||
|
|
||||||
guard let userId = accountTextField.text else { return }
|
guard let userId = accountTextField.text else { return }
|
||||||
guard let statusId = statusTextField.text else { return }
|
guard let statusId = statusTextField.text else { return }
|
||||||
|
guard let authenticationBox = self.context.authenticationService.activeMastodonAuthenticationBox.value else { return }
|
||||||
|
|
||||||
// itodo: delete them
|
// itodo: delete them
|
||||||
// 31803
|
// 31803
|
||||||
// 106093402888557459
|
// 106093402888557459
|
||||||
|
let viewModel = ReportViewModel(
|
||||||
|
context: self.context,
|
||||||
|
coordinator: self.coordinator,
|
||||||
|
domain: authenticationBox.domain,
|
||||||
|
userId: userId,
|
||||||
|
statusId: statusId
|
||||||
|
)
|
||||||
self.coordinator.present(
|
self.coordinator.present(
|
||||||
scene: .report(userId: userId, statusId: statusId),
|
scene: .report(viewModel: viewModel),
|
||||||
from: self, transition: .modal(animated: true, completion: nil))
|
from: self, transition: .modal(animated: true, completion: nil))
|
||||||
}
|
}
|
||||||
alertController.addAction(showAction)
|
alertController.addAction(showAction)
|
||||||
|
@ -13,10 +13,9 @@ import MastodonSDK
|
|||||||
import UIKit
|
import UIKit
|
||||||
import os.log
|
import os.log
|
||||||
|
|
||||||
class SettingsViewModel: NSObject, NeedsDependency {
|
class SettingsViewModel: NSObject {
|
||||||
// confirm set only once
|
// confirm set only once
|
||||||
weak var context: AppContext! { willSet { precondition(context == nil) } }
|
weak var context: AppContext! { willSet { precondition(context == nil) } }
|
||||||
weak var coordinator: SceneCoordinator! { willSet { precondition(coordinator == nil) } }
|
|
||||||
|
|
||||||
var dataSource: UITableViewDiffableDataSource<SettingsSection, SettingsItem>!
|
var dataSource: UITableViewDiffableDataSource<SettingsSection, SettingsItem>!
|
||||||
var disposeBag = Set<AnyCancellable>()
|
var disposeBag = Set<AnyCancellable>()
|
||||||
@ -87,9 +86,8 @@ class SettingsViewModel: NSObject, NeedsDependency {
|
|||||||
struct Output {
|
struct Output {
|
||||||
}
|
}
|
||||||
|
|
||||||
init(context: AppContext, coordinator: SceneCoordinator) {
|
init(context: AppContext) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.coordinator = coordinator
|
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user