mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-22 05:26:30 +00:00
Fix secondary navigation issue
This commit is contained in:
parent
933ded0233
commit
ab9cdc48ee
3 changed files with 20 additions and 5 deletions
|
@ -9,6 +9,7 @@ import ViewModels
|
|||
|
||||
final class AddIdentityViewController: UIViewController {
|
||||
private let viewModel: AddIdentityViewModel
|
||||
private let rootViewModel: RootViewModel
|
||||
private let displayWelcome: Bool
|
||||
private let scrollView = UIScrollView()
|
||||
private let stackView = UIStackView()
|
||||
|
@ -27,8 +28,9 @@ final class AddIdentityViewController: UIViewController {
|
|||
private let whatIsMastodonButton = UIButton(type: .system)
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
init(viewModel: AddIdentityViewModel, displayWelcome: Bool) {
|
||||
init(viewModel: AddIdentityViewModel, rootViewModel: RootViewModel, displayWelcome: Bool) {
|
||||
self.viewModel = viewModel
|
||||
self.rootViewModel = rootViewModel
|
||||
self.displayWelcome = displayWelcome
|
||||
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
@ -214,6 +216,14 @@ private extension AddIdentityViewController {
|
|||
.compactMap { $0 }
|
||||
.sink { [weak self] in self?.present(alertItem: $0) }
|
||||
.store(in: &cancellables)
|
||||
|
||||
// There is a situation adding an identity from secondary navigation in which
|
||||
// setting presentingSecondaryNavigation = false on the navigation view model
|
||||
// does not work and the old secondary navigation is presented over the new
|
||||
// main navigation. This is a hack to fix it.
|
||||
rootViewModel.$navigationViewModel.dropFirst()
|
||||
.sink { [weak self] _ in self?.dismiss(animated: true) }
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func initialDisplay() {
|
||||
|
|
|
@ -8,7 +8,6 @@ final class MainNavigationViewController: UITabBarController {
|
|||
private let viewModel: NavigationViewModel
|
||||
private let rootViewModel: RootViewModel
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
private weak var presentedSecondaryNavigation: UINavigationController?
|
||||
|
||||
init(viewModel: NavigationViewModel, rootViewModel: RootViewModel) {
|
||||
self.viewModel = viewModel
|
||||
|
@ -56,6 +55,8 @@ final class MainNavigationViewController: UITabBarController {
|
|||
}
|
||||
|
||||
private extension MainNavigationViewController {
|
||||
static let secondaryNavigationViewTag = UUID().hashValue
|
||||
|
||||
func setupViewControllers(pending: Bool) {
|
||||
var controllers: [UIViewController] = [
|
||||
TimelinesViewController(
|
||||
|
@ -132,12 +133,13 @@ private extension MainNavigationViewController {
|
|||
|
||||
let navigationController = UINavigationController(rootViewController: hostingController)
|
||||
|
||||
presentedSecondaryNavigation = navigationController
|
||||
navigationController.view.tag = Self.secondaryNavigationViewTag
|
||||
|
||||
present(navigationController, animated: true)
|
||||
}
|
||||
|
||||
func dismissSecondaryNavigation() {
|
||||
if presentedViewController == presentedSecondaryNavigation {
|
||||
if presentedViewController?.view.tag == Self.secondaryNavigationViewTag {
|
||||
dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,12 @@ import ViewModels
|
|||
struct AddIdentityView: UIViewControllerRepresentable {
|
||||
let viewModelClosure: () -> AddIdentityViewModel
|
||||
let displayWelcome: Bool
|
||||
@EnvironmentObject var rootViewModel: RootViewModel
|
||||
|
||||
func makeUIViewController(context: Context) -> AddIdentityViewController {
|
||||
AddIdentityViewController(viewModel: viewModelClosure(), displayWelcome: displayWelcome)
|
||||
AddIdentityViewController(viewModel: viewModelClosure(),
|
||||
rootViewModel: rootViewModel,
|
||||
displayWelcome: displayWelcome)
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: AddIdentityViewController, context: Context) {
|
||||
|
|
Loading…
Reference in a new issue