Skip to content

Commit

Permalink
0.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Mar 18, 2024
1 parent 33cccec commit 2deb6fc
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 38 deletions.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Examples/SyncUps/SyncUps.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@
repositoryURL = "https://github.com/dankinsoid/VDFlow";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.26.0;
minimumVersion = 4.27.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/dankinsoid/VDFlow",
"state" : {
"revision" : "c56440956274448d9a7efaa77e3f03b1d3104464",
"version" : "4.26.0"
"revision" : "564d551966b13d87cd5d757fd8d22ecc3d2fe866",
"version" : "4.27.0"
}
}
],
Expand Down
Binary file not shown.
12 changes: 6 additions & 6 deletions Examples/SyncUps/SyncUps/AppFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct AppView: View {

var body: some View {
NavigationSteps(
selection: $state.binding.path.selected
selection: _state.path.selected
) {
listView
detailView
Expand All @@ -93,36 +93,36 @@ struct AppView: View {
meetingView
}
}
.stepEnvironment($state.binding.path)
.stepEnvironment(_state.path)
}

private var listView: some View {
SyncUpsListView(store: $state.syncUpsList)
.step($state.binding.path.$list)
.step(_state.path.$list)
}

private var detailView: some View {
SyncUpDetailView(
store: $state.path.detail
.di(\.syncUpDetailDelegate, $state)
)
.step($state.binding.path.$detail)
.step(_state.path.$detail)
}

private var meetingView: some View {
MeetingView(
meeting: state.path.meeting.meeting,
syncUp: state.path.meeting.syncUp
)
.step($state.binding.path.$meeting)
.step(_state.path.$meeting)
}

private var recordView: some View {
RecordMeetingView(
store: $state.path.record
.di(\.recordMeetingDelegate, $state)
)
.step($state.binding.path.$record)
.step(_state.path.$record)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/SyncUps/SyncUps/SyncUpDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ struct SyncUpDetailView: View {
.speechRecognitionDeniedAlert(store: $state)
.speechRecognitionRestrictedAlert(store: $state)
.sheet(
isPresented: $state.binding.destination.isSelected(.edit)
isPresented: _state.destination.isSelected(.edit)
) {
NavigationStack {
SyncUpFormView(store: $state.destination.edit)
Expand Down
21 changes: 9 additions & 12 deletions Examples/SyncUps/SyncUps/SyncUpForm.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI
import VDStore
import VDFlow

struct SyncUpForm: Equatable {

Expand Down Expand Up @@ -46,38 +47,35 @@ extension Store<SyncUpForm> {
struct SyncUpFormView: View {

@ViewStore var state: SyncUpForm
@FocusState var focus: SyncUpForm.Field?

init(state: SyncUpForm, focus: SyncUpForm.Field? = nil) {
init(state: SyncUpForm) {
_state = ViewStore(wrappedValue: state)
self.focus = focus
}

init(store: Store<SyncUpForm>, focus: SyncUpForm.Field? = nil) {
init(store: Store<SyncUpForm>) {
_state = ViewStore(store)
self.focus = focus
}

var body: some View {
Form {
Section {
TextField("Title", text: $state.binding.syncUp.title)
.focused($focus, equals: .title)
TextField("Title", text: _state.syncUp.title)
.focused(_state.focus, equals: .title)
HStack {
Slider(value: $state.binding.syncUp.duration.minutes, in: 5 ... 30, step: 1) {
Slider(value: _state.syncUp.duration.minutes, in: 5 ... 30, step: 1) {
Text("Length")
}
Spacer()
Text(state.syncUp.duration.formatted(.units()))
}
ThemePicker(selection: $state.binding.syncUp.theme)
ThemePicker(selection: _state.syncUp.theme)
} header: {
Text("Sync-up Info")
}
Section {
ForEach($state.binding.syncUp.attendees) { attendee in
ForEach(_state.syncUp.attendees) { attendee in
TextField("Name", text: attendee.name)
.focused($focus, equals: .attendee(attendee.id))
.focused(_state.focus, equals: .attendee(attendee.id))
}
.onDelete { indices in
$state.deleteAttendees(atOffsets: indices)
Expand All @@ -90,7 +88,6 @@ struct SyncUpFormView: View {
Text("Attendees")
}
}
// .bind($state.binding.focus, to: $focus)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/SyncUps/SyncUps/SyncUpsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct SyncUpsListView: View {
.navigationTitle("Daily Sync-ups")
.syncUpsListAlert($state)
.sheet(
isPresented: $state.binding.destination.isSelected(.add)
isPresented: _state.destination.isSelected(.add)
) {
NavigationStack {
SyncUpFormView(store: $state.destination.add)
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public struct AppView: View {
LoginView(store: $state.login)
}
case .newGame:
NavigationSteps(selection: $state.binding.newGame.flow.selected) {
NavigationSteps(selection: _state.newGame.flow.selected) {
NewGameView(store: $state.newGame)
GameView(store: $state.newGame.flow.game)
.step($state.binding.newGame.flow.$game)
.step(_state.newGame.flow.$game)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public struct LoginView: View {
)

Section {
TextField("[email protected]", text: $state.binding.email)
TextField("[email protected]", text: _state.email)
.autocapitalization(.none)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)

SecureField("••••••••", text: $state.binding.password)
SecureField("••••••••", text: _state.password)
}

Button {
Expand All @@ -56,10 +56,10 @@ public struct LoginView: View {
.disabled(!state.isFormValid)
}
.disabled(state.isLoginRequestInFlight)
.alert(state.flow.alert, isPresented: $state.binding.flow.isSelected(.alert)) {
.alert(state.flow.alert, isPresented: _state.flow.isSelected(.alert)) {
Button("Ok") {}
}
.navigationDestination(isPresented: $state.binding.flow.isSelected(.twoFactor)) {
.navigationDestination(isPresented: _state.flow.isSelected(.twoFactor)) {
TwoFactorView(store: $state.flow.twoFactor)
}
.navigationTitle("Login")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct NewGameView: View {
public var body: some View {
Form {
Section {
TextField("Blob Sr.", text: $state.binding.xPlayerName)
TextField("Blob Sr.", text: _state.xPlayerName)
.autocapitalization(.words)
.disableAutocorrection(true)
.textContentType(.name)
Expand All @@ -25,7 +25,7 @@ public struct NewGameView: View {
}

Section {
TextField("Blob Jr.", text: $state.binding.oPlayerName)
TextField("Blob Jr.", text: _state.oPlayerName)
.autocapitalization(.words)
.disableAutocorrection(true)
.textContentType(.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct TwoFactorView: View {
Text(#"To confirm the second factor enter "1234" into the form."#)

Section {
TextField("1234", text: $state.binding.code)
TextField("1234", text: _state.code)
.keyboardType(.numberPad)
}

Expand All @@ -42,7 +42,7 @@ public struct TwoFactorView: View {
}
}
}
.alert(state.flow.alert, isPresented: $state.binding.flow.isSelected(.alert)) {
.alert(state.flow.alert, isPresented: _state.flow.isSelected(.alert)) {
Button("Ok") {}
}
.disabled(state.isFormDisabled)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/VDStore.git", from: "0.31.0")
.package(url: "https://github.com/dankinsoid/VDStore.git", from: "0.32.0")
],
targets: [
.target(name: "SomeProject", dependencies: ["VDStore"])
Expand Down
4 changes: 3 additions & 1 deletion Sources/VDStore/Dependencies/Dismiss.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
#if canImport(UIKit)
import UIKit

public extension StoreDIValues {

Expand Down Expand Up @@ -58,3 +59,4 @@ private extension [UIViewController] {
return nil
}
}
#endif
17 changes: 14 additions & 3 deletions Sources/VDStore/ViewStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ import SwiftUI
@available(iOS 14.0, macOS 11.00, tvOS 14.0, watchOS 7.0, *)
@MainActor
@propertyWrapper
@dynamicMemberLookup
public struct ViewStore<State>: DynamicProperty {

private let property: Property
@Environment(\.storeDIValues) private var transformDI

public var wrappedValue: State {
get { projectedValue.state }
nonmutating set { projectedValue.state = newValue }
get { store.state }
nonmutating set { store.state = newValue }
}

public var projectedValue: Store<State> {
public var projectedValue: Store<State> {
store
}

public var store: Store<State> {
let result: Store<State>
switch property {
case let .stateObject(observable):
Expand Down Expand Up @@ -56,6 +61,12 @@ public struct ViewStore<State>: DynamicProperty {
self.init(Store(wrappedValue: state))
}

public subscript<LocalValue>(
dynamicMember keyPath: WritableKeyPath<State, LocalValue>
) -> Binding<LocalValue> {
store.binding[dynamicMember: keyPath]
}

@MainActor
private enum Property: DynamicProperty {

Expand Down

0 comments on commit 2deb6fc

Please sign in to comment.