ekazaev / route-composer

Protocol oriented, Cocoa UI abstractions based library that helps to handle view controllers composition, navigation and deep linking tasks in the iOS application. Can be used as the universal replacement for the Coordinator pattern.
MIT License
896 stars 63 forks source link

Use .from(OtherDestinationStep) only with same context? #52

Closed ArtSumin closed 4 years ago

ArtSumin commented 4 years ago

I want to use a view controllers chain in one navigation controller. I have to use the same context for each view controller on the stack. How to be in this case? Use type Any for context and later convert to the desired type?

ekazaev commented 4 years ago

@ArtSumin

You can use Any or Dictionary or any other type. But unless your navigation is completely dynamic I would strongly advice agains it. Most likely with a wider view on your business task you may come with the right answer.

I'll give an example that helps some people.

Lets say you have a booking app that has a home screen, a hotel screen and the room screen.

Chain will look like: Home -> Hotel -> Room

So the correct way to navigate to all of this screen will be to descibe the common context for the hotel and a room screen Something like:

struct BookingContext {
    let hotelId: String
    let roomId: String?
}

And keep the Home context type as Any? as home can be presented without any context.

With such configuration you will be able to navigate to any of this screens