Skip to content

Commit

Permalink
4.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Mar 16, 2024
1 parent 173c72d commit 77834d6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion Sources/VDFlow/MutateID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

public struct MutateID: Comparable, Hashable, Codable, Sendable {

private var mutationDate: UInt64?
var mutationDate: UInt64?

init() {
}
Expand Down
29 changes: 17 additions & 12 deletions Sources/VDFlow/StateStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct StateStep<Value>: DynamicProperty {
)
}

public func unselect(stepsCount: Int = 1) {
public func deselect(stepsCount: Int = 1) {
guard !unselectClosure.isEmpty else {
Environment(\.presentationMode).wrappedValue.wrappedValue.dismiss()
return
Expand Down Expand Up @@ -87,31 +87,36 @@ private enum UnselectKey: EnvironmentKey {

public extension View {

func step<Root: StepsCollection, Value>(
_ binding: StepBinding<Root, Value>
) -> some View {
step(binding.$root, binding.keyPath)
}
func step<Root: StepsCollection, Value>(
_ binding: StepBinding<Root, Value>
) -> some View {
step(
Binding {
binding.root[keyPath: binding.keyPath]
} set: {
binding.root[keyPath: binding.keyPath] = $0
}
)
}

func step<Root: StepsCollection, Value>(
_ binding: Binding<Root>,
_ keyPath: WritableKeyPath<Root, StepWrapper<Root, Value>>
_ binding: Binding<StepWrapper<Root, Value>>
) -> 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<Value>(_ binding: Binding<Value>) -> some View {
Expand Down
4 changes: 4 additions & 0 deletions Sources/VDFlow/StepWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public struct StepWrapper<Parent: StepsCollection, Value>: Identifiable {
_mutateID._update()
}

public mutating func deselect() {
_mutateID.mutationDate = nil
}

public mutating func select(with value: Value) {
wrappedValue = value
select()
Expand Down

0 comments on commit 77834d6

Please sign in to comment.