@@ -27,23 +27,18 @@ public final class TabLinkNavigator {
2727 public let routeBuilderItemList : [ RouteBuilderOf < TabPartialNavigator > ]
2828 public let dependency : DependencyType
2929
30- public var tabRootNavigators : [ TabRootNavigationController ] = [ ]
30+ public var tabRootPartialNavigators : [ TabPartialNavigator ] = [ ]
3131
3232 public var owner : LinkNavigatorItemSubscriberProtocol ? = . none
3333
3434 public weak var mainController : UITabBarController ?
3535
3636 public var currentTabRootPath : String ? {
37- guard let currentController = mainController? . selectedViewController else { return . none }
38- let currentTabRootController = tabRootNavigators. first ( where: { $0. navigationController == currentController } )
39-
40- return currentTabRootController? . matchPath
37+ ( ( mainController? . selectedViewController as? UINavigationController ) ? . viewControllers. first as? MatchPathUsable ) ? . matchPath
4138 }
4239
4340 public var currentPath : String ? {
44- ( tabRootNavigators. first ( where: {
45- $0. navigationController == mainController? . selectedViewController
46- } ) ? . navigationController. topViewController as? MatchPathUsable ) ? . matchPath
41+ ( ( mainController? . selectedViewController as? UINavigationController ) ? . topViewController as? MatchPathUsable ) ? . matchPath
4742 }
4843
4944 // MARK: Internal
@@ -60,14 +55,18 @@ public final class TabLinkNavigator {
6055}
6156
6257extension TabLinkNavigator {
63- func targetController( targetTabPath: String ) -> UINavigationController ? {
64- tabRootNavigators. first ( where: { $0. matchPath == targetTabPath } ) ? . navigationController
58+ public func targetController( targetTabPath: String ) -> UINavigationController ? {
59+ tabRootPartialNavigators. first ( where: { $0. getCurrentRootPaths ( ) . first == targetTabPath } ) ? . currentTabNavigationController
60+ }
61+
62+ public func targetPartialNavigator( tabPath: String ) -> TabPartialNavigator ? {
63+ tabRootPartialNavigators. first ( where: { $0. getCurrentRootPaths ( ) . first == tabPath } )
6564 }
6665}
6766
6867extension TabLinkNavigator {
6968 public func launch( tagItemList: [ TabItem ] ) -> [ UINavigationController ] {
70- let tabPartialNavigators = tagItemList
69+ let partialNavigators = tagItemList
7170 . reduce ( [ ( Bool, TabPartialNavigator) ] ( ) ) { curr, next in
7271 let newNavigatorList = TabPartialNavigator (
7372 rootNavigator: self ,
@@ -77,16 +76,16 @@ extension TabLinkNavigator {
7776 return curr + [ ( next. prefersLargeTitles, newNavigatorList) ]
7877 }
7978
80- tabRootNavigators = tabPartialNavigators
79+ self . tabRootPartialNavigators = partialNavigators. map ( \. 1 )
80+
81+ return partialNavigators
8182 . map { ( prefersLargeTitles, navigator) in
8283 let partialNavigationVC = navigator. launch ( rootPath: navigator. tabItem. linkItem. pathList. first ?? " " )
8384 let item = tagItemList. first ( where: { $0. linkItem == navigator. tabItem. linkItem } )
8485 partialNavigationVC. navigationController. tabBarItem = item? . tabItem
8586 partialNavigationVC. navigationController. navigationBar. prefersLargeTitles = prefersLargeTitles
86- return partialNavigationVC
87+ return partialNavigationVC. navigationController
8788 }
88-
89- return tabRootNavigators. map ( \. navigationController)
9089 }
9190}
9291
@@ -149,8 +148,7 @@ extension TabLinkNavigator {
149148 }
150149
151150 public func moveTab( targetPath: String ) {
152- guard let targetController = tabRootNavigators. first ( where: { $0. matchPath == targetPath } ) ? . navigationController
153- else { return }
151+ guard let targetController = tabRootPartialNavigators. first ( where: { $0. getCurrentRootPaths ( ) . first == targetPath } ) ? . currentTabNavigationController else { return }
154152
155153 if mainController? . selectedViewController == targetController {
156154 targetController. popToRootViewController ( animated: true )
@@ -166,40 +164,19 @@ extension TabLinkNavigator {
166164 let currentController = modalController ?? fullSheetController ?? mainController? . selectedViewController
167165 currentController? . present ( model. build ( ) , animated: true )
168166 }
169- }
170167
171- extension UINavigationController {
172- private func currentItemList( ) -> [ String ] {
173- viewControllers. compactMap { $0 as? MatchPathUsable } . map ( \. matchPath)
174- }
168+ /// Sends event to navigators that match path of link item
169+ public func send( linkItem: LinkItem ) {
170+ var matchPathUsables : [ MatchPathUsable ] = [ ]
175171
176- private func merge( new: [ UIViewController ] , isAnimated: Bool ) {
177- setViewControllers ( viewControllers + new, animated: isAnimated)
178- }
179-
180- private func back( isAnimated: Bool ) {
181- popViewController ( animated: isAnimated)
182- }
172+ matchPathUsables = tabRootPartialNavigators
173+ . flatMap ( \. currentTabNavigationController. viewControllers)
174+ . compactMap { $0 as? MatchPathUsable }
183175
184- private func clear( isAnimated: Bool ) {
185- setViewControllers ( [ ] , animated: isAnimated)
186- }
187-
188- private func push( viewController: UIViewController ? , isAnimated: Bool ) {
189- guard let viewController else { return }
190- pushViewController ( viewController, animated: isAnimated)
191- }
192-
193- private func replace( viewController: [ UIViewController ] , isAnimated: Bool ) {
194- setViewControllers ( viewController, animated: isAnimated)
195- }
196-
197- private func popTo( viewController: UIViewController ? , isAnimated: Bool ) {
198- guard let viewController else { return }
199- popToViewController ( viewController, animated: isAnimated)
200- }
201-
202- private func dropLast( ) -> [ UIViewController ] {
203- Array ( viewControllers. dropLast ( ) )
176+ matchPathUsables
177+ . filter { linkItem. pathList. contains ( $0. matchPath) }
178+ . forEach {
179+ $0. eventSubscriber? . receive ( encodedItemString: linkItem. encodedItemString)
180+ }
204181 }
205182}
0 commit comments