Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeepLink chain not executed as expected #246

Open
anhntsi opened this issue Jun 23, 2023 · 1 comment
Open

DeepLink chain not executed as expected #246

anhntsi opened this issue Jun 23, 2023 · 1 comment

Comments

@anhntsi
Copy link

anhntsi commented Jun 23, 2023

Thank you for the wonderful Coordinator library. I am having an issue related to deeplink chain.

The issue is that the deeplink only runs to the MarketsRoute route, while the StockMarketRoute does not execute.

return .multiple(
                .dismissToRoot(),
                .popToRoot(),
                deepLink(AppRoute.home, HomeRoute.markets, MarketsRoute.stocks, StockMarketRoute.counterDetail)
)

I will explain a little bit about the Coordinator in the demo project. HomeTabCoordinator is a tab bar controller that contains 3 tabs: NewsCoordinator, MarketsCoordinator, UsersCoordinator. MarketsCoordinator is a page view controller that has 2 pages: StockMarketCoordinator and UTMarketCoordinator.

Can you help me identify where the problem is?

@matthewshehan
Copy link

This really depends on how you're using XCoodinator. I'd have to see how you're using XCoordinator to give you better advice, but my general solution to this is to wrap your ViewControllers in a wrapper object that conforms to Presentable then override this function in that that wrapper where the strongRouter is the Coordinator that presents that ViewController

public func router<R: Route>(for route: R) -> StrongRouter<R>?

basically when you transiton a ViewController despite UIViewController conforming to presentable, it itself is not a Router the coordinator that displays that ViewController is the Router so you have to point to that router in that function in order for deep linking to execute as expected.

You could do something like this

class  MyModule: Presentable {
  let viewController: UIViewController! 
  unowned var presentingCoordinator: MyCoordinator 
  
  init(viewController: MyViewController, coordinator: MyCoordinator ) {
    self.viewController = viewController 
    self.coordinator = coordinator 
  }
  public func router<R: Route>(for route: R) -> StrongRouter<R>? {
      coordinator.strongRouter 
  }
}

.... 

class MyCoordinator {
... 

  override func prepareForTransition(on route: MyRoute) -> TransitionType {
    switch route {
      case .initialRoute: 
         let module = MyModule(viewController: MyViewController(), coordinator: self)
         return .present(module) 
     .... 
    }
  }
}

now since you presented the module that knows about the router Deep linking should start working properly. This problem actually comes up again in other situations. This is my general workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants