Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions TICoordinatorKit/Classes/Routable/Stack/StackRoutable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ public protocol StackRoutable: ModalRoutable {
var topModule: Presentable? { get }

func push(_ module: Presentable?)
func push(_ module: Presentable?,
completion: (() -> ())?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

отступ поехал

func push(_ module: Presentable?, animated: Bool)
func push(_ module: Presentable?,
animated: Bool,
configurationClosure: ConfigurationClosure?)
func push(_ module: Presentable?,
animated: Bool,
completion: (() -> ())?)

func push(_ module: Presentable?,
animated: Bool,
Expand Down
30 changes: 27 additions & 3 deletions TICoordinatorKit/Classes/Routable/Stack/StackRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import UIKit

open class StackRouter: StackRoutable {
open class StackRouter: NSObject, StackRoutable, UINavigationControllerDelegate {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Определение себя делегатом навигейшен контроллера в StackRouter убивает подписку в кастомной реализации UINavigationController в проекте. Кажется, это совершенно не очевидное поведение библиотеки


private var completions: [UIViewController: () -> ()]

Expand All @@ -45,6 +45,10 @@ open class StackRouter: StackRoutable {
self.rootController = rootController
self.headModule = rootController.topViewController
self.completions = [:]

super.init()

self.rootController?.delegate = self
}

// MARK: - StackRoutable
Expand All @@ -53,6 +57,12 @@ open class StackRouter: StackRoutable {
push(module, animated: true)
}

public func push(_ module: Presentable?,
completion: (() -> ())?) {

push(module, animated: true, completion: completion)
}

public func push(_ module: Presentable?, animated: Bool) {
push(module, animated: animated, configurationClosure: nil, completion: nil)
}
Expand All @@ -64,7 +74,12 @@ open class StackRouter: StackRoutable {
push(module, animated: animated, configurationClosure: configurationClosure, completion: nil)
}


public func push(_ module: Presentable?,
animated: Bool,
completion: (() -> ())?) {

push(module, animated: animated, configurationClosure: nil, completion: completion)
}

public func push(_ module: Presentable?,
animated: Bool,
Expand Down Expand Up @@ -200,10 +215,19 @@ open class StackRouter: StackRoutable {
completions[controller]?()
completions.removeValue(forKey: controller)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишние пробелы

public func runCompletionsChain(of controllers: [UIViewController]) {
controllers.forEach { [weak self] controller in
self?.runCompletion(for: controller)
}
}

public func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
guard let poppedViewController = navigationController.transitionCoordinator?.viewController(forKey: .from),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно добавить ссылку на источник проблемы и более подробное решение? Так как на первый взгляд неочевидно, что именно здесь пытаемся добиться.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В мои времена это делалось через CATransaction setCompletionBlock кхе-кхе
https://stackoverflow.com/a/27229945

!navigationController.viewControllers.contains(poppedViewController) else {
return
}

runCompletion(for: poppedViewController)
}
}