diff --git a/README.md b/README.md index d0c8a6e..30bdae9 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ import PackageDescription let package = Package( name: "SomeProject", dependencies: [ - .package(url: "https://github.com/dankinsoid/VDFlow.git", from: "4.16.0") + .package(url: "https://github.com/dankinsoid/VDFlow.git", from: "4.17.0") ], targets: [ .target(name: "SomeProject", dependencies: ["VDFlow"]) diff --git a/Sources/VDFlow/MutateID.swift b/Sources/VDFlow/MutateID.swift index 46f8476..93471a9 100644 --- a/Sources/VDFlow/MutateID.swift +++ b/Sources/VDFlow/MutateID.swift @@ -2,7 +2,7 @@ import Foundation public struct MutateID: Comparable, Hashable, Codable, Sendable { - private var mutationDate: UInt64? + var mutationDate: UInt64? init() { } diff --git a/Sources/VDFlow/StateStep.swift b/Sources/VDFlow/StateStep.swift index 423c857..ecf09bf 100644 --- a/Sources/VDFlow/StateStep.swift +++ b/Sources/VDFlow/StateStep.swift @@ -46,7 +46,7 @@ public struct StateStep: DynamicProperty { ) } - public func unselect(stepsCount: Int = 1) { + public func deselect(stepsCount: Int = 1) { guard !unselectClosure.isEmpty else { Environment(\.presentationMode).wrappedValue.wrappedValue.dismiss() return @@ -87,31 +87,36 @@ private enum UnselectKey: EnvironmentKey { public extension View { - func step( - _ binding: StepBinding - ) -> some View { - step(binding.$root, binding.keyPath) - } + func step( + _ binding: StepBinding + ) -> some View { + step( + Binding { + binding.root[keyPath: binding.keyPath] + } set: { + binding.root[keyPath: binding.keyPath] = $0 + } + ) + } func step( - _ binding: Binding, - _ keyPath: WritableKeyPath> + _ binding: Binding> ) -> some View { stepEnvironment( - binding[dynamicMember: keyPath.appending(path: \.wrappedValue)] + binding[dynamicMember: \.wrappedValue] ) .transformEnvironment(\.unselectStep) { $0.insert( { if let none = (Root.AllSteps.self as? ExpressibleByNilLiteral.Type)?.init(nilLiteral: ()) as? Root.AllSteps { - binding.wrappedValue.selected = none + binding.wrappedValue.deselect() } }, at: 0 ) } - .tag(binding.wrappedValue[keyPath: keyPath].id) - .stepTag(binding.wrappedValue[keyPath: keyPath].id) + .tag(binding.wrappedValue.id) + .stepTag(binding.wrappedValue.id) } func stepEnvironment(_ binding: Binding) -> some View { diff --git a/Sources/VDFlow/StepWrapper.swift b/Sources/VDFlow/StepWrapper.swift index 8537c7b..4aa80a3 100644 --- a/Sources/VDFlow/StepWrapper.swift +++ b/Sources/VDFlow/StepWrapper.swift @@ -28,6 +28,10 @@ public struct StepWrapper: Identifiable { _mutateID._update() } + public mutating func deselect() { + _mutateID.mutationDate = nil + } + public mutating func select(with value: Value) { wrappedValue = value select()