Skip to content

Commit

Permalink
4.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Mar 17, 2024
1 parent 184e1ae commit 7a13d15
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 163 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.18.0")
.package(url: "https://github.com/dankinsoid/VDFlow.git", from: "4.19.0")
],
targets: [
.target(name: "SomeProject", dependencies: ["VDFlow"])
Expand Down
41 changes: 0 additions & 41 deletions Sources/VDFlow/NavigationView+Ext.swift

This file was deleted.

27 changes: 10 additions & 17 deletions Sources/VDFlow/StateStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SwiftUI
///
/// @StateStep var router = StepsStruct()
/// let stepState = StateStep(stepBinding)
@dynamicMemberLookup
@propertyWrapper
public struct StateStep<Value>: DynamicProperty {

Expand Down Expand Up @@ -44,16 +43,16 @@ public struct StateStep<Value>: DynamicProperty {
}
}

public extension StateStep where Value: StepsCollection {

subscript<A>(dynamicMember keyPath: WritableKeyPath<Value, StepWrapper<Value, A>>) -> Binding<StepSelection<Value, A>> {
Binding {
wrappedValue[keyPath]
} set: {
wrappedValue[keyPath] = $0
}
}
}
//public extension StateStep where Value: StepsCollection {
//
// subscript<A>(dynamicMember keyPath: WritableKeyPath<Value, StepWrapper<Value, A>>) -> Binding<StepSelection<Value, A>> {
// Binding {
// wrappedValue[keyPath]
// } set: {
// wrappedValue[keyPath] = $0
// }
// }
//}

public extension StateStep where Value == EmptyStep {

Expand All @@ -72,12 +71,6 @@ extension EnvironmentValues {

public extension View {

func step<Root: StepsCollection, Value>(
_ binding: StepBinding<Root, Value>
) -> some View {
step(binding.wrapper)
}

func step<Root: StepsCollection, Value>(
_ binding: Binding<StepWrapper<Root, Value>>
) -> some View {
Expand Down
31 changes: 0 additions & 31 deletions Sources/VDFlow/StepBinding.swift

This file was deleted.

118 changes: 59 additions & 59 deletions Sources/VDFlow/StepSelection.swift
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
import Foundation

@dynamicMemberLookup
public struct StepSelection<Parent: StepsCollection, Value>: Identifiable {

public var parent: Parent
public var value: Value {
get { parent[keyPath: keyPath].wrappedValue }
set { parent[keyPath: keyPath].wrappedValue = newValue }
}
public var id: Parent.AllSteps { parent[keyPath: keyPath].id }

let keyPath: WritableKeyPath<Parent, StepWrapper<Parent, Value>>
var wrapper: StepWrapper<Parent, Value> {
get { parent[keyPath: keyPath] }
set { parent[keyPath: keyPath] = newValue }
}

@_disfavoredOverload
public var isSelected: Bool {
parent.selected == parent[keyPath: keyPath].id
}

public mutating func select() {
parent[keyPath: keyPath].select()
}

public mutating func select(with value: Value) {
parent[keyPath: keyPath].select(with: value)
}
}

extension StepSelection where Parent.AllSteps: ExpressibleByNilLiteral {

public var isSelected: Bool {
get { parent.selected == parent[keyPath: keyPath].id }
set { parent.selected = newValue ? parent[keyPath: keyPath].id : nil }
}

public mutating func deselect() {
parent.selected = nil
}
}

extension StepSelection where Value: StepsCollection {

public subscript<T>(dynamicMember keyPath: WritableKeyPath<Value, StepWrapper<Value, T>>) -> StepSelection<Value, T> {
get { StepSelection<Value, T>(parent: value, keyPath: keyPath) }
set { value = newValue.parent }
}
}

extension StepsCollection {

public subscript<Value>(_ keyPath: WritableKeyPath<Self, StepWrapper<Self, Value>>) -> StepSelection<Self, Value> {
get { StepSelection(parent: self, keyPath: keyPath) }
set { self = newValue.parent }
}
}
//import Foundation
//
//@dynamicMemberLookup
//public struct StepSelection<Parent: StepsCollection, Value>: Identifiable {
//
// public var parent: Parent
// public var value: Value {
// get { parent[keyPath: keyPath].wrappedValue }
// set { parent[keyPath: keyPath].wrappedValue = newValue }
// }
// public var id: Parent.AllSteps { parent[keyPath: keyPath].id }
//
// let keyPath: WritableKeyPath<Parent, StepWrapper<Parent, Value>>
// var wrapper: StepWrapper<Parent, Value> {
// get { parent[keyPath: keyPath] }
// set { parent[keyPath: keyPath] = newValue }
// }
//
// @_disfavoredOverload
// public var isSelected: Bool {
// parent.selected == parent[keyPath: keyPath].id
// }
//
// public mutating func select() {
// parent[keyPath: keyPath].select()
// }
//
// public mutating func select(with value: Value) {
// parent[keyPath: keyPath].select(with: value)
// }
//}
//
//extension StepSelection where Parent.AllSteps: ExpressibleByNilLiteral {
//
// public var isSelected: Bool {
// get { parent.selected == parent[keyPath: keyPath].id }
// set { parent.selected = newValue ? parent[keyPath: keyPath].id : nil }
// }
//
// public mutating func deselect() {
// parent.selected = nil
// }
//}
//
//extension StepSelection where Value: StepsCollection {
//
// public subscript<T>(dynamicMember keyPath: WritableKeyPath<Value, StepWrapper<Value, T>>) -> StepSelection<Value, T> {
// get { StepSelection<Value, T>(parent: value, keyPath: keyPath) }
// set { value = newValue.parent }
// }
//}
//
//extension StepsCollection {
//
// public subscript<Value>(_ keyPath: WritableKeyPath<Self, StepWrapper<Self, Value>>) -> StepSelection<Self, Value> {
// get { StepSelection(parent: self, keyPath: keyPath) }
// set { self = newValue.parent }
// }
//}
9 changes: 0 additions & 9 deletions Sources/VDFlow/StepWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public extension StepsCollection {
}

@propertyWrapper
@dynamicMemberLookup
public struct StepWrapper<Parent: StepsCollection, Value>: Identifiable {

public let id: Parent.AllSteps
Expand Down Expand Up @@ -46,14 +45,6 @@ public extension StepWrapper where Value == EmptyStep {
}
}

public extension StepWrapper where Value: StepsCollection {

subscript<T>(dynamicMember keyPath: WritableKeyPath<Value, StepWrapper<Value, T>>) -> StepSelection<Value, T> {
get { StepSelection(parent: wrappedValue, keyPath: keyPath) }
set { wrappedValue = newValue.parent }
}
}

public extension StepWrapper {

init<T>(_ id: Parent.AllSteps) where T? == Value {
Expand Down
11 changes: 6 additions & 5 deletions Tests/VDFlowTests/VDFlowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ final class VDFlowTestsCase: XCTestCase {

func testSelection() {
var value: TabSteps = .tab2
value.$tab3.$screen2.isSelected = true
value.$tab3
XCTAssertEqual(value.selected, .tab3)
}
}

Expand Down Expand Up @@ -78,12 +79,12 @@ struct SomeView: View {

var body: some View {
Picker(selection: $tabs.selected) {
Text("Tab 1").step(_tabs.$tab1)
Text("Tab 2").step(_tabs.$tab2)
Text("Tab 3").step(_tabs.$tab3)
Text("Tab 1").step($tabs.$tab1)
Text("Tab 2").step($tabs.$tab2)
Text("Tab 3").step($tabs.$tab3)
} label: {
}
.sheet(isPresented: _tabs.$tab3.$screen2.isSelected) {
.sheet(isPresented: $tabs.tab3.isSelected(.screen2)) {
}
}
}

0 comments on commit 7a13d15

Please sign in to comment.