Refactoring
This commit is contained in:
parent
1359b80a8e
commit
19176f955c
|
@ -30,7 +30,7 @@ class ShareExtensionNavigationViewController: UINavigationController {
|
||||||
}
|
}
|
||||||
|
|
||||||
setViewControllers(
|
setViewControllers(
|
||||||
[NewStatusViewController(viewModel: newStatusViewModel)],
|
[NewStatusViewController(viewModel: newStatusViewModel, rootViewModel: nil)],
|
||||||
animated: false)
|
animated: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,15 @@ final class MainNavigationViewController: UITabBarController {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
viewModel.$presentedNewStatusViewModel.sink { [weak self] in
|
||||||
|
if let newStatusViewModel = $0 {
|
||||||
|
self?.presentNewStatus(newStatusViewModel: newStatusViewModel)
|
||||||
|
} else {
|
||||||
|
self?.dismissNewStatus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
|
|
||||||
viewModel.$presentingSecondaryNavigation.sink { [weak self] in
|
viewModel.$presentingSecondaryNavigation.sink { [weak self] in
|
||||||
if $0 {
|
if $0 {
|
||||||
self?.presentSecondaryNavigation()
|
self?.presentSecondaryNavigation()
|
||||||
|
@ -56,6 +65,7 @@ final class MainNavigationViewController: UITabBarController {
|
||||||
|
|
||||||
private extension MainNavigationViewController {
|
private extension MainNavigationViewController {
|
||||||
static let secondaryNavigationViewTag = UUID().hashValue
|
static let secondaryNavigationViewTag = UUID().hashValue
|
||||||
|
static let newStatusViewTag = UUID().hashValue
|
||||||
|
|
||||||
func setupViewControllers(pending: Bool) {
|
func setupViewControllers(pending: Bool) {
|
||||||
var controllers: [UIViewController] = [
|
var controllers: [UIViewController] = [
|
||||||
|
@ -96,18 +106,9 @@ private extension MainNavigationViewController {
|
||||||
func setupNewStatusButton() {
|
func setupNewStatusButton() {
|
||||||
let newStatusButtonView = NewStatusButtonView(primaryAction: UIAction { [weak self] _ in
|
let newStatusButtonView = NewStatusButtonView(primaryAction: UIAction { [weak self] _ in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
let newStatusViewModel = self.rootViewModel.newStatusViewModel(
|
|
||||||
identityContext: self.viewModel.identityContext)
|
|
||||||
let newStatusViewController = NewStatusViewController(viewModel: newStatusViewModel)
|
|
||||||
let newStatusNavigationController = UINavigationController(rootViewController: newStatusViewController)
|
|
||||||
|
|
||||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
self.viewModel.presentedNewStatusViewModel =
|
||||||
newStatusNavigationController.modalPresentationStyle = .fullScreen
|
self.rootViewModel.newStatusViewModel(identityContext: self.viewModel.identityContext)
|
||||||
} else {
|
|
||||||
newStatusNavigationController.isModalInPresentation = true
|
|
||||||
}
|
|
||||||
|
|
||||||
self.present(newStatusNavigationController, animated: true)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
view.addSubview(newStatusButtonView)
|
view.addSubview(newStatusButtonView)
|
||||||
|
@ -158,6 +159,28 @@ private extension MainNavigationViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func presentNewStatus(newStatusViewModel: NewStatusViewModel) {
|
||||||
|
let newStatusViewController = NewStatusViewController(viewModel: newStatusViewModel,
|
||||||
|
rootViewModel: rootViewModel)
|
||||||
|
let navigationController = UINavigationController(rootViewController: newStatusViewController)
|
||||||
|
|
||||||
|
if UIDevice.current.userInterfaceIdiom == .phone {
|
||||||
|
navigationController.modalPresentationStyle = .overFullScreen
|
||||||
|
} else {
|
||||||
|
navigationController.isModalInPresentation = true
|
||||||
|
}
|
||||||
|
|
||||||
|
navigationController.view.tag = Self.newStatusViewTag
|
||||||
|
|
||||||
|
present(navigationController, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dismissNewStatus() {
|
||||||
|
if presentedViewController?.view.tag == Self.newStatusViewTag {
|
||||||
|
dismiss(animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func handle(navigation: Navigation) {
|
func handle(navigation: Navigation) {
|
||||||
let vc: UIViewController
|
let vc: UIViewController
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import ViewModels
|
||||||
// swiftlint:disable file_length
|
// swiftlint:disable file_length
|
||||||
final class NewStatusViewController: UIViewController {
|
final class NewStatusViewController: UIViewController {
|
||||||
private let viewModel: NewStatusViewModel
|
private let viewModel: NewStatusViewModel
|
||||||
|
private let rootViewModel: RootViewModel?
|
||||||
private let scrollView = UIScrollView()
|
private let scrollView = UIScrollView()
|
||||||
private let stackView = UIStackView()
|
private let stackView = UIStackView()
|
||||||
private let activityIndicatorView = UIActivityIndicatorView(style: .large)
|
private let activityIndicatorView = UIActivityIndicatorView(style: .large)
|
||||||
|
@ -24,8 +25,9 @@ final class NewStatusViewController: UIViewController {
|
||||||
private let documentPickerResuls = PassthroughSubject<[URL]?, Never>()
|
private let documentPickerResuls = PassthroughSubject<[URL]?, Never>()
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
|
||||||
init(viewModel: NewStatusViewModel) {
|
init(viewModel: NewStatusViewModel, rootViewModel: RootViewModel?) {
|
||||||
self.viewModel = viewModel
|
self.viewModel = viewModel
|
||||||
|
self.rootViewModel = rootViewModel
|
||||||
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
|
||||||
|
@ -241,7 +243,7 @@ private extension NewStatusViewController {
|
||||||
if let extensionContext = extensionContext {
|
if let extensionContext = extensionContext {
|
||||||
extensionContext.completeRequest(returningItems: nil)
|
extensionContext.completeRequest(returningItems: nil)
|
||||||
} else {
|
} else {
|
||||||
presentingViewController?.dismiss(animated: true)
|
rootViewModel?.navigationViewModel?.presentedNewStatusViewModel = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -452,20 +452,10 @@ private extension TableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func compose(inReplyToViewModel: StatusViewModel?, redraft: Status?) {
|
func compose(inReplyToViewModel: StatusViewModel?, redraft: Status?) {
|
||||||
let newStatusViewModel = rootViewModel.newStatusViewModel(
|
rootViewModel.navigationViewModel?.presentedNewStatusViewModel = rootViewModel.newStatusViewModel(
|
||||||
identityContext: viewModel.identityContext,
|
identityContext: viewModel.identityContext,
|
||||||
inReplyTo: inReplyToViewModel,
|
inReplyTo: inReplyToViewModel,
|
||||||
redraft: redraft)
|
redraft: redraft)
|
||||||
let newStatusViewController = NewStatusViewController(viewModel: newStatusViewModel)
|
|
||||||
let navigationController = UINavigationController(rootViewController: newStatusViewController)
|
|
||||||
|
|
||||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
|
||||||
navigationController.modalPresentationStyle = .overFullScreen
|
|
||||||
} else {
|
|
||||||
navigationController.isModalInPresentation = true
|
|
||||||
}
|
|
||||||
|
|
||||||
present(navigationController, animated: true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func confirmDelete(statusViewModel: StatusViewModel, redraft: Bool) {
|
func confirmDelete(statusViewModel: StatusViewModel, redraft: Bool) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ public final class NavigationViewModel: ObservableObject {
|
||||||
public let navigations: AnyPublisher<Navigation, Never>
|
public let navigations: AnyPublisher<Navigation, Never>
|
||||||
|
|
||||||
@Published public private(set) var recentIdentities = [Identity]()
|
@Published public private(set) var recentIdentities = [Identity]()
|
||||||
|
@Published public var presentedNewStatusViewModel: NewStatusViewModel?
|
||||||
@Published public var presentingSecondaryNavigation = false
|
@Published public var presentingSecondaryNavigation = false
|
||||||
@Published public var alertItem: AlertItem?
|
@Published public var alertItem: AlertItem?
|
||||||
|
|
||||||
|
@ -110,6 +111,10 @@ public extension NavigationViewModel {
|
||||||
titleComponents: ["follow-requests"])))
|
titleComponents: ["follow-requests"])))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func navigate(pushNotification: PushNotification) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
func viewModel(timeline: Timeline) -> CollectionItemsViewModel {
|
func viewModel(timeline: Timeline) -> CollectionItemsViewModel {
|
||||||
CollectionItemsViewModel(
|
CollectionItemsViewModel(
|
||||||
collectionService: identityContext.service.navigationService.timelineService(timeline: timeline),
|
collectionService: identityContext.service.navigationService.timelineService(timeline: timeline),
|
||||||
|
|
|
@ -178,6 +178,12 @@ private extension RootViewModel {
|
||||||
if identityId != navigationViewModel?.identityContext.identity.id {
|
if identityId != navigationViewModel?.identityContext.identity.id {
|
||||||
identitySelected(id: identityId, immediate: false, notify: true)
|
identitySelected(id: identityId, immediate: false, notify: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$navigationViewModel.first { $0?.identityContext.identity.id == identityId }
|
||||||
|
// Ensure views are set up if switching accounts
|
||||||
|
.delay(for: .milliseconds(1), scheduler: DispatchQueue.main)
|
||||||
|
.sink { $0?.navigate(pushNotification: pushNotification) }
|
||||||
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
func notifyIdentityChange(identityContext: IdentityContext) {
|
func notifyIdentityChange(identityContext: IdentityContext) {
|
||||||
|
|
Loading…
Reference in New Issue