diff --git a/Samples/TicTacToe/Sources/Authentication/LoginScreen.swift b/Samples/TicTacToe/Sources/Authentication/LoginScreen.swift index 305b0aac3..2219a212a 100644 --- a/Samples/TicTacToe/Sources/Authentication/LoginScreen.swift +++ b/Samples/TicTacToe/Sources/Authentication/LoginScreen.swift @@ -18,8 +18,8 @@ import SwiftUI import Workflow import WorkflowSwiftUI -struct LoginScreen: SwiftUIScreen { - var actionSink: Sink +struct LoginScreen: SwiftUIScreen, Equatable { + var actionSink: ScreenActionSink var title: String var email: String var password: String diff --git a/Samples/TicTacToe/Sources/Authentication/LoginWorkflow.swift b/Samples/TicTacToe/Sources/Authentication/LoginWorkflow.swift index 885ce6cd2..f3149f37a 100644 --- a/Samples/TicTacToe/Sources/Authentication/LoginWorkflow.swift +++ b/Samples/TicTacToe/Sources/Authentication/LoginWorkflow.swift @@ -73,7 +73,7 @@ extension LoginWorkflow { func render(state: LoginWorkflow.State, context: RenderContext) -> Rendering { LoginScreen( - actionSink: context.makeSink(of: Action.self), + actionSink: .init(context.makeSink(of: Action.self)), title: "Welcome! Please log in to play TicTacToe!", email: state.email, password: state.password diff --git a/WorkflowSwiftUI/Sources/ObservableValue.swift b/WorkflowSwiftUI/Sources/ObservableValue.swift index e38a4c396..f10640574 100644 --- a/WorkflowSwiftUI/Sources/ObservableValue.swift +++ b/WorkflowSwiftUI/Sources/ObservableValue.swift @@ -105,6 +105,23 @@ public final class ObservableValue: ObservableObject { } } +public struct ScreenActionSink: Equatable { + private let sink: Sink + + // TODO: Only allow this to be initialized by `WorkflowNode.SubtreeManager.Context`? + public init(_ sink: Sink) { + self.sink = sink + } + + public func send(_ value: Value) { + sink.send(value) + } + + public static func == (lhs: ScreenActionSink, rhs: ScreenActionSink) -> Bool { + true + } +} + #if canImport(UIKit) public extension ObservableValue where Value: SwiftUIScreen { diff --git a/WorkflowSwiftUI/Sources/SwiftUIScreen.swift b/WorkflowSwiftUI/Sources/SwiftUIScreen.swift index 068e64bd8..72abd1ab2 100644 --- a/WorkflowSwiftUI/Sources/SwiftUIScreen.swift +++ b/WorkflowSwiftUI/Sources/SwiftUIScreen.swift @@ -27,7 +27,7 @@ public protocol SwiftUIScreen: Screen { @ViewBuilder static func makeView(model: ObservableValue) -> Content - var actionSink: Sink { get } + var actionSink: ScreenActionSink { get } static var isDuplicate: ((Self, Self) -> Bool)? { get } }