-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da33775
commit 2cd48b8
Showing
5 changed files
with
217 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import ComposableArchitecture | ||
import SwiftUI | ||
|
||
struct FormView: View { | ||
let store: StoreOf<AlertDemoReducer.Form> | ||
|
||
var body: some View { | ||
WithViewStore(store) { formViewStore in | ||
Form { | ||
Section { | ||
Text("Scrim Settings") | ||
Toggle("Dismiss on Scrim Tap", isOn: formViewStore.binding(\.$dismissOnScrimTap)) | ||
HStack { | ||
Text("Opacity: \(formViewStore.scrimPercentage)") | ||
Slider( | ||
value: formViewStore.binding(\.$scrimOpacity), | ||
in: 0.1...1, | ||
step: 0.1 | ||
) | ||
} | ||
} | ||
|
||
Section { | ||
Text("Alert presentation starting position") | ||
HStack { | ||
Text("X: \(Int(formViewStore.alertStartX))") | ||
.frame(width: 80, alignment: .leading) | ||
Slider( | ||
value: formViewStore.binding(\.$alertStartX), | ||
in: -1000...1000, | ||
step: 100 | ||
) | ||
} | ||
HStack { | ||
Text("Y: \(Int(formViewStore.alertStartY))") | ||
.frame(width: 80, alignment: .leading) | ||
Slider( | ||
value: formViewStore.binding(\.$alertStartY), | ||
in: -1000...1000, | ||
step: 100 | ||
) | ||
} | ||
} | ||
|
||
Section { | ||
Text("Alert presented position") | ||
HStack { | ||
Text("X: \(Int(formViewStore.alertPresentedX))") | ||
.frame(width: 80, alignment: .leading) | ||
|
||
Slider( | ||
value: formViewStore.binding(\.$alertPresentedX), | ||
in: -300...300, | ||
step: 100 | ||
) | ||
} | ||
HStack { | ||
Text("Y: \(Int(formViewStore.alertPresentedY))") | ||
.frame(width: 80, alignment: .leading) | ||
Slider( | ||
value: formViewStore.binding(\.$alertPresentedY), | ||
in: -300...300, | ||
step: 100 | ||
) | ||
} | ||
} | ||
|
||
Section { | ||
Text("Alert dismissal ending position") | ||
HStack { | ||
Text("X: \(Int(formViewStore.alertEndX))") | ||
.frame(width: 80, alignment: .leading) | ||
Slider( | ||
value: formViewStore.binding(\.$alertEndX), | ||
in: -1000...1000, | ||
step: 100 | ||
) | ||
} | ||
HStack { | ||
Text("Y: \(Int(formViewStore.alertEndY))") | ||
.frame(width: 80, alignment: .leading) | ||
Slider( | ||
value: formViewStore.binding(\.$alertEndY), | ||
in: -1000...1000, | ||
step: 100 | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import ComposableArchitecture | ||
import SwiftUI | ||
import TCACustomAlert | ||
|
||
struct AlertDemoReducer: ReducerProtocol { | ||
|
||
struct State: Equatable { | ||
|
||
var alertState: CustomTcaAlert.State = .init() | ||
|
||
var form: Form.State { | ||
get { | ||
.init( | ||
dismissOnScrimTap: alertState.dismissOnScrimTap, | ||
scrimOpacity: alertState.endScrimOpacity, | ||
alertStartY: alertState.alertStartPosition.height, | ||
alertStartX: alertState.alertStartPosition.width, | ||
alertPresentedY: alertState.alertPresentedPosition.height, | ||
alertPresentedX: alertState.alertPresentedPosition.width, | ||
alertEndY: alertState.alertEndPosition.height, | ||
alertEndX: alertState.alertEndPosition.width | ||
) | ||
} | ||
set { | ||
self.alertState.dismissOnScrimTap = newValue.dismissOnScrimTap | ||
self.alertState.endScrimOpacity = newValue.scrimOpacity | ||
self.alertState.alertStartPosition = .init(width: newValue.alertStartX, height: newValue.alertStartY) | ||
self.alertState.alertPresentedPosition = .init(width: newValue.alertPresentedX, height: newValue.alertPresentedY) | ||
self.alertState.alertEndPosition = .init(width: newValue.alertEndX, height: newValue.alertEndY) | ||
|
||
} | ||
} | ||
} | ||
|
||
enum Action: Equatable { | ||
case alert(CustomTcaAlert.Action) | ||
case form(Form.Action) | ||
} | ||
|
||
var body: some ReducerProtocol<State, Action> { | ||
Scope(state: \.form, action: /Action.form) { | ||
Form() | ||
} | ||
|
||
Scope(state: \.alertState, action: /Action.alert) { | ||
CustomTcaAlert() | ||
} | ||
} | ||
|
||
struct Form: ReducerProtocol { | ||
struct State: Equatable { | ||
@BindableState var dismissOnScrimTap = true | ||
@BindableState var scrimOpacity = 0.6 | ||
|
||
@BindableState var alertStartY: CGFloat = 500 | ||
@BindableState var alertStartX: CGFloat = 500 | ||
|
||
@BindableState var alertPresentedY: CGFloat = 0 | ||
@BindableState var alertPresentedX: CGFloat = 0 | ||
|
||
@BindableState var alertEndY: CGFloat = -500 | ||
@BindableState var alertEndX: CGFloat = -500 | ||
|
||
var scrimPercentage: String { | ||
// Simple formatting for this use case. | ||
String(format: "%.f%%", scrimOpacity * 100) | ||
} | ||
} | ||
|
||
enum Action: Equatable, BindableAction { | ||
case binding(BindingAction<State>) | ||
} | ||
|
||
var body: some ReducerProtocol<State, Action> { | ||
BindingReducer() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters