| 1 |
//
|
|
| 2 |
// RouteComposer
|
|
| 3 |
// InlineStackIteratingFinder.swift
|
|
| 4 |
// https://github.com/ekazaev/route-composer
|
|
| 5 |
//
|
|
| 6 |
// Created by Eugene Kazaev in 2018-2022.
|
|
| 7 |
// Distributed under the MIT license.
|
|
| 8 |
//
|
|
| 9 |
// Become a sponsor:
|
|
| 10 |
// https://github.com/sponsors/ekazaev
|
|
| 11 |
//
|
|
| 12 |
|
|
| 13 |
import UIKit
|
|
| 14 |
|
|
| 15 |
/// `InlineStackIteratingFinder`. Might be useful for the configuration testing.
|
|
| 16 |
public struct InlineStackIteratingFinder<VC: UIViewController, C>: StackIteratingFinder {
|
|
| 17 |
|
|
| 18 |
// MARK: Associated types
|
|
| 19 |
|
|
| 20 |
/// Type of `UIViewController` that `Factory` can build
|
|
| 21 |
public typealias ViewController = VC
|
|
| 22 |
|
|
| 23 |
/// `Context` to be passed into `UIViewController`
|
|
| 24 |
public typealias Context = C
|
|
| 25 |
|
|
| 26 |
// MARK: Properties
|
|
| 27 |
|
|
| 28 |
public var iterator: StackIterator
|
|
| 29 |
|
|
| 30 |
let inlineBock: (VC, C) -> Bool
|
|
| 31 |
|
|
| 32 |
// MARK: Functions
|
|
| 33 |
|
|
| 34 |
/// Constructor
|
|
| 35 |
/// - Parameters:
|
|
| 36 |
/// - iterator: A `StackIterator` is to be used by `InlineStackIteratingFinder`
|
|
| 37 |
/// - inlineBock: A block to be called when `StackIteratingFinder.isTarget(...)` is requested.
|
|
| 38 |
public init(iterator: StackIterator = RouteComposerDefaults.shared.stackIterator,
|
|
| 39 |
_ inlineBock: @escaping (VC, C) -> Bool) {
|
! |
| 40 |
self.iterator = iterator
|
! |
| 41 |
self.inlineBock = inlineBock
|
! |
| 42 |
}
|
! |
| 43 |
|
|
| 44 |
public func isTarget(_ viewController: VC, with context: C) -> Bool {
|
! |
| 45 |
inlineBock(viewController, context)
|
! |
| 46 |
}
|
! |
| 47 |
|
|
| 48 |
}
|
|
| 49 |
|
|
| 50 |
/// Extension to use `DefaultStackIterator` as default iterator.
|
|
| 51 |
public extension InlineStackIteratingFinder {
|
|
| 52 |
|
|
| 53 |
/// Constructor
|
|
| 54 |
///
|
|
| 55 |
/// - Parameters:
|
|
| 56 |
/// - options: A combination of the `SearchOptions`
|
|
| 57 |
/// - startingPoint: `DefaultStackIterator.StartingPoint` value
|
|
| 58 |
/// - windowProvider: `WindowProvider` instance.
|
|
| 59 |
/// - containerAdapterLocator: A `ContainerAdapterLocator` instance.
|
|
| 60 |
/// - inlineBock: A block to be called when `StackIteratingFinder.isTarget(...)` is requested.
|
|
| 61 |
init(options: SearchOptions,
|
|
| 62 |
startingPoint: DefaultStackIterator.StartingPoint = .topmost,
|
|
| 63 |
windowProvider: WindowProvider = RouteComposerDefaults.shared.windowProvider,
|
|
| 64 |
containerAdapterLocator: ContainerAdapterLocator = RouteComposerDefaults.shared.containerAdapterLocator,
|
|
| 65 |
predicate inlineBock: @escaping (VC, C) -> Bool) {
|
! |
| 66 |
self.init(iterator: DefaultStackIterator(options: options, startingPoint: startingPoint, windowProvider: windowProvider, containerAdapterLocator: containerAdapterLocator), inlineBock)
|
! |
| 67 |
}
|
! |
| 68 |
|
|
| 69 |
}
|
|