Skip to content
Snippets Groups Projects
BackupCoordinator.swift 1.21 KiB
Newer Older
import UIKit
Ahmed Shehata's avatar
Ahmed Shehata committed
import Shared
import Presentation

public protocol BackupCoordinating {
    func toDrawer(
Ahmed Shehata's avatar
Ahmed Shehata committed
        _: UIViewController,
        from: UIViewController
    )

    func toPassphrase(
        from: UIViewController,
        cancelClosure: @escaping EmptyClosure,
        passphraseClosure: @escaping StringClosure
    )
}

public struct BackupCoordinator: BackupCoordinating {
    var bottomPresenter: Presenting = BottomPresenter()

    var passphraseFactory: (@escaping EmptyClosure, @escaping StringClosure) -> UIViewController
Ahmed Shehata's avatar
Ahmed Shehata committed

    public init(
        passphraseFactory: @escaping (@escaping EmptyClosure, @escaping StringClosure) -> UIViewController
Ahmed Shehata's avatar
Ahmed Shehata committed
    ) {
        self.passphraseFactory = passphraseFactory
    }
}

public extension BackupCoordinator {
    func toDrawer(
Ahmed Shehata's avatar
Ahmed Shehata committed
        _ screen: UIViewController,
        from parent: UIViewController
    ) {
        bottomPresenter.present(screen, from: parent)
    }

    func toPassphrase(
        from parent: UIViewController,
        cancelClosure: @escaping EmptyClosure,
        passphraseClosure: @escaping StringClosure
    ) {
        let screen = passphraseFactory(cancelClosure, passphraseClosure)
        bottomPresenter.present(screen, from: parent)
    }
}