rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
907 stars 95 forks source link

Update ViewWrapperCoordinator to allow viewfactory to access coordinator #110

Closed mattjung closed 1 year ago

mattjung commented 1 year ago

Allows for the ability to access the coordinator i.e self within the view factory

Example of use:

final class NavigationCoordinatorWithClose<T: Coordinatable>: ViewWrapperCoordinator<T, AnyView> {

    init(_ embedded: T) {
        super.init(embedded) { coordinator in { view in
            AnyView(
                NavigationView {
                    view
                        .toolbar {
                            ToolbarItem(placement: .navigationBarLeading) {
                                Button("Close") {
                                    coordinator.parent?.dismissChild(coordinator: coordinator, action: nil)
                                }
                            }
                       }
                 }
            )
        }}
    }
}