mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-20 09:11:33 +01:00
* Internal: rename `Store.{state,stateSubject}`
Both an internal readability win and will make it easier to provide a
public `state` property in the future.
* wip
78 lines
2.7 KiB
Swift
78 lines
2.7 KiB
Swift
import SwiftUI
|
|
|
|
extension View {
|
|
/// Displays a legacy alert when then store's state becomes non-`nil`, and dismisses it when it
|
|
/// becomes `nil`.
|
|
///
|
|
/// - Parameters:
|
|
/// - store: A store that is focused on ``PresentationState`` and ``PresentationAction`` for an
|
|
/// alert.
|
|
@available(iOS, introduced: 13, deprecated: 100000, message: "use `View.alert(store:) instead.")
|
|
@available(
|
|
macOS, introduced: 10.15, deprecated: 100000, message: "use `View.alert(store:) instead."
|
|
)
|
|
@available(tvOS, introduced: 13, deprecated: 100000, message: "use `View.alert(store:) instead.")
|
|
@available(
|
|
watchOS, introduced: 6, deprecated: 100000, message: "use `View.alert(store:) instead."
|
|
)
|
|
public func legacyAlert<ButtonAction>(
|
|
store: Store<PresentationState<AlertState<ButtonAction>>, PresentationAction<ButtonAction>>
|
|
) -> some View {
|
|
self.legacyAlert(store: store, state: { $0 }, action: { $0 })
|
|
}
|
|
|
|
/// Displays a legacy alert when then store's state becomes non-`nil`, and dismisses it when it
|
|
/// becomes `nil`.
|
|
///
|
|
/// - Parameters:
|
|
/// - store: A store that is focused on ``PresentationState`` and ``PresentationAction`` for an
|
|
/// alert.
|
|
/// - toDestinationState: A transformation to extract alert state from the presentation state.
|
|
/// - fromDestinationAction: A transformation to embed alert actions into the presentation
|
|
/// action.
|
|
@available(
|
|
iOS,
|
|
introduced: 13,
|
|
deprecated: 100000,
|
|
message: "use `View.alert(store:state:action:) instead."
|
|
)
|
|
@available(
|
|
macOS,
|
|
introduced: 10.15,
|
|
deprecated: 100000,
|
|
message: "use `View.alert(store:state:action:) instead."
|
|
)
|
|
@available(
|
|
tvOS,
|
|
introduced: 13,
|
|
deprecated: 100000,
|
|
message: "use `View.alert(store:state:action:) instead."
|
|
)
|
|
@available(
|
|
watchOS,
|
|
introduced: 6,
|
|
deprecated: 100000,
|
|
message: "use `View.alert(store:state:action:) instead."
|
|
)
|
|
public func legacyAlert<State, Action, ButtonAction>(
|
|
store: Store<PresentationState<State>, PresentationAction<Action>>,
|
|
state toDestinationState: @escaping (_ state: State) -> AlertState<ButtonAction>?,
|
|
action fromDestinationAction: @escaping (_ alertAction: ButtonAction) -> Action
|
|
) -> some View {
|
|
self.presentation(
|
|
store: store, state: toDestinationState, action: fromDestinationAction
|
|
) { `self`, $item, _ in
|
|
let alertState = store.withState { $0.wrappedValue.flatMap(toDestinationState) }
|
|
self.alert(item: $item) { _ in
|
|
Alert(alertState!) { action in
|
|
if let action = action {
|
|
store.send(.presented(fromDestinationAction(action)))
|
|
} else {
|
|
store.send(.dismiss)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|