-
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.
Merge pull request #39 from Ryu0118/feature/swiftui-alert
Support AlertState and ConfirmationDialogState
- Loading branch information
Showing
18 changed files
with
302 additions
and
17 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
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
13 changes: 13 additions & 0 deletions
13
Sources/SimplexArchitecture/Internal/Dependencies+isTesting.swift
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,13 @@ | ||
import Foundation | ||
|
||
enum IsTestingKey: DependencyKey { | ||
static let liveValue: Bool = _XCTIsTesting | ||
static let testValue: Bool = _XCTIsTesting | ||
} | ||
|
||
extension DependencyValues { | ||
var isTesting: Bool { | ||
get { self[IsTestingKey.self] } | ||
set { self[IsTestingKey.self] = newValue } | ||
} | ||
} |
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,2 @@ | ||
@_exported import SwiftUINavigation | ||
@_exported import Dependencies |
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
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,66 @@ | ||
import SwiftUI | ||
|
||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) | ||
public extension View { | ||
func alert<Target: ActionSendable>( | ||
target: Target, | ||
unwrapping value: Binding<AlertState<Target.Reducer.Action>?> | ||
) -> some View { | ||
self.alert( | ||
(value.wrappedValue?.title).map(Text.init) ?? Text(""), | ||
isPresented: value.isPresent(), | ||
presenting: value.wrappedValue, | ||
actions: { alertState in | ||
ForEach(alertState.buttons) { button in | ||
Button(role: button.role.map(ButtonRole.init)) { | ||
switch button.action.type { | ||
case let .send(action): | ||
if let action = action { | ||
target.send(action) | ||
} | ||
case let .animatedSend(action, animation): | ||
if let action = action { | ||
target.send(action, animation: animation) | ||
} | ||
} | ||
} label: { | ||
Text(button.label) | ||
} | ||
} | ||
}, | ||
message: { $0.message.map { Text($0) } } | ||
) | ||
} | ||
|
||
func alert<Target: ActionSendable>( | ||
target: Target, | ||
unwrapping value: Binding<AlertState<Target.Reducer.ReducerAction>?> | ||
) -> some View { | ||
self.alert( | ||
(value.wrappedValue?.title).map(Text.init) ?? Text(""), | ||
isPresented: value.isPresent(), | ||
presenting: value.wrappedValue, | ||
actions: { alertState in | ||
ForEach(alertState.buttons) { button in | ||
Button(role: button.role.map(ButtonRole.init)) { | ||
switch button.action.type { | ||
case let .send(action): | ||
if let action = action { | ||
_ = target.store.sendAction(action, target: target) | ||
} | ||
case let .animatedSend(action, animation): | ||
if let action = action { | ||
_ = withAnimation(animation) { | ||
target.store.sendAction(action, target: target) | ||
} | ||
} | ||
} | ||
} label: { | ||
Text(button.label) | ||
} | ||
} | ||
}, | ||
message: { $0.message.map { Text($0) } } | ||
) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
Sources/SimplexArchitecture/SwiftUI/ConfirmationDialog.swift
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,68 @@ | ||
import SwiftUI | ||
|
||
@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) | ||
public extension View { | ||
func confirmationDialog<Target: ActionSendable>( | ||
target: Target, | ||
unwrapping value: Binding<ConfirmationDialogState<Target.Reducer.Action>?> | ||
) -> some View { | ||
self.confirmationDialog( | ||
value.wrappedValue.flatMap { Text($0.title) } ?? Text(""), | ||
isPresented: value.isPresent(), | ||
titleVisibility: value.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic, | ||
presenting: value.wrappedValue, | ||
actions: { confirmationDialogState in | ||
ForEach(confirmationDialogState.buttons) { button in | ||
Button(role: button.role.map(ButtonRole.init)) { | ||
switch button.action.type { | ||
case let .send(action): | ||
if let action = action { | ||
target.send(action) | ||
} | ||
case let .animatedSend(action, animation): | ||
if let action = action { | ||
target.send(action, animation: animation) | ||
} | ||
} | ||
} label: { | ||
Text(button.label) | ||
} | ||
} | ||
}, | ||
message: { $0.message.map { Text($0) } } | ||
) | ||
} | ||
|
||
func confirmationDialog<Target: ActionSendable>( | ||
target: Target, | ||
unwrapping value: Binding<ConfirmationDialogState<Target.Reducer.ReducerAction>?> | ||
) -> some View { | ||
self.confirmationDialog( | ||
value.wrappedValue.flatMap { Text($0.title) } ?? Text(""), | ||
isPresented: value.isPresent(), | ||
titleVisibility: value.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic, | ||
presenting: value.wrappedValue, | ||
actions: { confirmationDialogState in | ||
ForEach(confirmationDialogState.buttons) { button in | ||
Button(role: button.role.map(ButtonRole.init)) { | ||
switch button.action.type { | ||
case let .send(action): | ||
if let action = action { | ||
_ = target.store.sendAction(action, target: target) | ||
} | ||
case let .animatedSend(action, animation): | ||
if let action = action { | ||
_ = withAnimation(animation) { | ||
target.store.sendAction(action, target: target) | ||
} | ||
} | ||
} | ||
} label: { | ||
Text(button.label) | ||
} | ||
} | ||
}, | ||
message: { $0.message.map { Text($0) } } | ||
) | ||
} | ||
} |
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
8 changes: 6 additions & 2 deletions
8
Tests/SimplexArchitectureTests/DependenciesOverrideModifierTests.swift
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
Oops, something went wrong.