Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into prerelease/1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jun 28, 2023
2 parents 0e8ccf2 + 89f80fe commit 47d302c
Show file tree
Hide file tree
Showing 65 changed files with 1,031 additions and 762 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation",
"state" : {
"revision" : "db81007362f998654239021ca9308a264e59d3e2",
"version" : "0.7.2"
"revision" : "2aa885e719087ee19df251c08a5980ad3e787f12",
"version" : "0.8.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/CaseStudies/SwiftUICaseStudies/00-RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ struct RootView: View {
}
}
.navigationTitle("Case Studies")
.onAppear { ViewStore(self.store.stateless).send(.onAppear) }
.onAppear { self.store.send(.onAppear) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,26 @@ struct BindingFormView: View {
}

HStack {
TextField("Type here", text: viewStore.binding(\.$text))
TextField("Type here", text: viewStore.$text)
.disableAutocorrection(true)
.foregroundStyle(viewStore.toggleIsOn ? Color.secondary : .primary)
Text(alternate(viewStore.text))
}
.disabled(viewStore.toggleIsOn)

Toggle(
"Disable other controls",
isOn: viewStore.binding(\.$toggleIsOn)
.resignFirstResponder()
)
Toggle("Disable other controls", isOn: viewStore.$toggleIsOn.resignFirstResponder())

Stepper(
"Max slider value: \(viewStore.stepCount)",
value: viewStore.binding(\.$stepCount),
value: viewStore.$stepCount,
in: 0...100
)
.disabled(viewStore.toggleIsOn)

HStack {
Text("Slider value: \(Int(viewStore.sliderValue))")

Slider(value: viewStore.binding(\.$sliderValue), in: 0...Double(viewStore.stepCount))
Slider(value: viewStore.$sliderValue, in: 0...Double(viewStore.stepCount))
.tint(.accentColor)
}
.disabled(viewStore.toggleIsOn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ struct FocusDemoView: View {
AboutView(readMe: readMe)

VStack {
TextField("Username", text: viewStore.binding(\.$username))
TextField("Username", text: viewStore.$username)
.focused($focusedField, equals: .username)
SecureField("Password", text: viewStore.binding(\.$password))
SecureField("Password", text: viewStore.$password)
.focused($focusedField, equals: .password)
Button("Sign In") {
viewStore.send(.signInButtonTapped)
Expand All @@ -66,7 +66,7 @@ struct FocusDemoView: View {
}
.textFieldStyle(.roundedBorder)
}
.synchronize(viewStore.binding(\.$focusedField), self.$focusedField)
.synchronize(viewStore.$focusedField, self.$focusedField)
}
.navigationTitle("Focus demo")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct NavigationDemoView: View {

Section {
Button("Go to A → B → C") {
ViewStore(self.store.stateless).send(.goToABCButtonTapped)
self.store.send(.goToABCButtonTapped)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Examples/Integration/Integration/BindingLocalTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ struct BindingLocalTestCaseView: View {
NavigationStackStore(self.store.scope(state: \.path, action: { .path($0) })) {
VStack {
Button("Full-screen-cover") {
ViewStore(self.store.stateless).send(.fullScreenCoverButtonTapped)
self.store.send(.fullScreenCoverButtonTapped)
}
Button("Navigation destination") {
ViewStore(self.store.stateless).send(.navigationDestinationButtonTapped)
self.store.send(.navigationDestinationButtonTapped)
}
NavigationLink("Path", state: Child.State())
Button("Popover") {
ViewStore(self.store.stateless).send(.popoverButtonTapped)
self.store.send(.popoverButtonTapped)
}
Button("Sheet") {
ViewStore(self.store.stateless).send(.sheetButtonTapped)
self.store.send(.sheetButtonTapped)
}
}
.fullScreenCover(
Expand Down Expand Up @@ -135,9 +135,9 @@ private struct ChildView: View {
Button("Dismiss") {
self.dismiss()
}
TextField("Text", text: viewStore.binding(\.$text))
TextField("Text", text: viewStore.$text)
Button(viewStore.sendOnDisappear ? "Don't send onDisappear" : "Send onDisappear") {
viewStore.binding(\.$sendOnDisappear).wrappedValue.toggle()
viewStore.$sendOnDisappear.wrappedValue.toggle()
}
}
.onDisappear {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct NavigationStackBindingTestCaseView: View {
}

var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
WithViewStore(self.store, observe: { $0 }) { viewStore in
NavigationStack(
path: viewStore.binding(
get: \.path,
Expand Down
12 changes: 6 additions & 6 deletions Examples/Integration/Integration/PresentationItemTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ struct PresentationItemTestCaseView: View {
@ViewBuilder
var core: some View {
Button("Child A") {
ViewStore(self.store.stateless).send(.childAButtonTapped)
self.store.send(.childAButtonTapped)
}
Button("Child B") {
ViewStore(self.store.stateless).send(.childBButtonTapped)
self.store.send(.childBButtonTapped)
}
}

Expand All @@ -97,7 +97,7 @@ struct PresentationItemTestCaseView: View {
) { store in
Text("Child A")
Button("Swap") {
ViewStore(store.stateless).send(.swapButtonTapped)
store.send(.swapButtonTapped)
}
}
case .childB:
Expand All @@ -107,7 +107,7 @@ struct PresentationItemTestCaseView: View {
) { store in
Text("Child B")
Button("Swap") {
ViewStore(store.stateless).send(.swapButtonTapped)
store.send(.swapButtonTapped)
}
}
}
Expand All @@ -125,7 +125,7 @@ struct PresentationItemTestCaseView: View {
) { store in
Text("Child A")
Button("Swap") {
ViewStore(store.stateless).send(.swapButtonTapped)
store.send(.swapButtonTapped)
}
}
.sheet(
Expand All @@ -135,7 +135,7 @@ struct PresentationItemTestCaseView: View {
) { store in
Text("Child B")
Button("Swap") {
ViewStore(store.stateless).send(.swapButtonTapped)
store.send(.swapButtonTapped)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private struct ChildView: View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
VStack {
Text("Count: \(viewStore.count)")
TextField("Text field", text: viewStore.binding(\.$text))
TextField("Text field", text: viewStore.$text)
Button("Child dismiss") {
viewStore.send(.childDismissButtonTapped)
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Integration/Integration/SwitchStoreTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct SwitchStoreTestCaseView: View {
}

var body: some View {
Button("Swap") { ViewStore(store.stateless).send(.swap) }
Button("Swap") { self.store.send(.swap) }
SwitchStore(self.store) {
switch $0 {
case .screenA:
Expand Down
10 changes: 5 additions & 5 deletions Examples/Standups/Standups/StandupForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ struct StandupFormView: View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
Form {
Section {
TextField("Title", text: viewStore.binding(\.$standup.title))
TextField("Title", text: viewStore.$standup.title)
.focused(self.$focus, equals: .title)
HStack {
Slider(value: viewStore.binding(\.$standup.duration).seconds, in: 5...30, step: 1) {
Slider(value: viewStore.$standup.duration.seconds, in: 5...30, step: 1) {
Text("Length")
}
Spacer()
Text(viewStore.standup.duration.formatted(.units()))
}
ThemePicker(selection: viewStore.binding(\.$standup.theme))
ThemePicker(selection: viewStore.$standup.theme)
} header: {
Text("Standup Info")
}
Section {
ForEach(viewStore.binding(\.$standup.attendees)) { $attendee in
ForEach(viewStore.$standup.attendees) { $attendee in
TextField("Name", text: $attendee.name)
.focused(self.$focus, equals: .attendee(attendee.id))
}
Expand All @@ -94,7 +94,7 @@ struct StandupFormView: View {
Text("Attendees")
}
}
.bind(viewStore.binding(\.$focus), to: self.$focus)
.bind(viewStore.$focus, to: self.$focus)
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions Examples/TicTacToe/tic-tac-toe/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ let package = Package(
name: "GameSwiftUI",
dependencies: ["GameCore"]
),
.testTarget(
name: "GameSwiftUITests",
dependencies: ["GameSwiftUI"]
),
.target(
name: "GameUIKit",
dependencies: ["GameCore"]
Expand All @@ -114,10 +110,6 @@ let package = Package(
"TwoFactorSwiftUI",
]
),
.testTarget(
name: "LoginSwiftUITests",
dependencies: ["LoginSwiftUI"]
),
.target(
name: "LoginUIKit",
dependencies: [
Expand All @@ -144,10 +136,6 @@ let package = Package(
"NewGameCore",
]
),
.testTarget(
name: "NewGameSwiftUITests",
dependencies: ["NewGameSwiftUI"]
),
.target(
name: "NewGameUIKit",
dependencies: [
Expand All @@ -171,10 +159,6 @@ let package = Package(
name: "TwoFactorSwiftUI",
dependencies: ["TwoFactorCore"]
),
.testTarget(
name: "TwoFactorSwiftUITests",
dependencies: ["TwoFactorSwiftUI"]
),
.target(
name: "TwoFactorUIKit",
dependencies: ["TwoFactorCore"]
Expand Down
32 changes: 15 additions & 17 deletions Examples/TicTacToe/tic-tac-toe/Sources/LoginCore/LoginCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ import TwoFactorCore
public struct Login: Reducer, Sendable {
public struct State: Equatable {
@PresentationState public var alert: AlertState<AlertAction>?
public var email = ""
@BindingState public var email = ""
public var isFormValid = false
public var isLoginRequestInFlight = false
public var password = ""
@BindingState public var password = ""
@PresentationState public var twoFactor: TwoFactor.State?

public init() {}
}

public enum Action: Equatable, Sendable {
public enum Action: Equatable {
case alert(PresentationAction<AlertAction>)
case emailChanged(String)
case passwordChanged(String)
case loginButtonTapped
case loginResponse(TaskResult<AuthenticationResponse>)
case twoFactor(PresentationAction<TwoFactor.Action>)
case view(View)

public enum View: BindableAction, Equatable {
case binding(BindingAction<State>)
case loginButtonTapped
}
}

public enum AlertAction: Equatable, Sendable {}
Expand All @@ -31,16 +34,12 @@ public struct Login: Reducer, Sendable {
public init() {}

public var body: some Reducer<State, Action> {
BindingReducer(action: /Action.view)
Reduce { state, action in
switch action {
case .alert:
return .none

case let .emailChanged(email):
state.email = email
state.isFormValid = !state.email.isEmpty && !state.password.isEmpty
return .none

case let .loginResponse(.success(response)):
state.isLoginRequestInFlight = false
if response.twoFactorRequired {
Expand All @@ -53,12 +52,14 @@ public struct Login: Reducer, Sendable {
state.isLoginRequestInFlight = false
return .none

case let .passwordChanged(password):
state.password = password
case .twoFactor:
return .none

case .view(.binding):
state.isFormValid = !state.email.isEmpty && !state.password.isEmpty
return .none

case .loginButtonTapped:
case .view(.loginButtonTapped):
state.isLoginRequestInFlight = true
return .run { [email = state.email, password = state.password] send in
await send(
Expand All @@ -71,9 +72,6 @@ public struct Login: Reducer, Sendable {
)
)
}

case .twoFactor:
return .none
}
}
.ifLet(\.$alert, action: /Action.alert)
Expand Down
Loading

0 comments on commit 47d302c

Please sign in to comment.