rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
926 stars 98 forks source link

Make NavigationRoute initialiser public #139

Closed mattjung closed 1 month ago

mattjung commented 1 month ago

Currently, NavigationRoute can only be initialised using a property wrapper. However, protocols in Swift do not yet support property wrappers as properties.

There are cases where we'd like to define possible navigation routes in a protocol and allow the protocol’s conforming types to implement them. This PR makes the NavigationRoute initialiser public, allowing routes to be defined in protocols and instantiated without the need for a property wrapper in the implementation.

public protocol ScreenBProtocol: NavigationCoordinatable {}

public protocol ScreenAProtocol: NavigationCoordinatable {

    associatedtype ScreenB: ScreenBProtocol

    var screenB: NavigationRoute<Self, Presentation, (), ScreenB> { get }
}

public final class ScreenACoordinator<
    ScreenB: ScreenBProtocol,
>: ScreenAProtocol {

    public typealias I = ScreenACoordinator<ScreenB>

    public let stack: Stinsen.NavigationStack<I>

    @Root var root = makeRoot
    public var screenB = NavigationRoute(wrappedValue: I.makeScreenB, .modal)

    ...
}
mattjung commented 1 month ago

Not needed