Files
swift-composable-architectu…/Sources/ComposableArchitecture/SwiftUI/Deprecated/ActionSheet.swift
Stephen Celis 5ba7943402 Internal: rename Store.{state,stateSubject} (#2538)
* 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
2023-10-31 14:45:57 -07:00

89 lines
2.9 KiB
Swift

import SwiftUI
extension View {
/// Displays an action sheet 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.confirmationDialog(store:)' instead."
)
@available(macOS, unavailable)
@available(
tvOS,
introduced: 13,
deprecated: 100000,
message: "use 'View.confirmationDialog(store:)' instead."
)
@available(
watchOS,
introduced: 6,
deprecated: 100000,
message: "use 'View.confirmationDialog(store:)' instead."
)
public func actionSheet<ButtonAction>(
store: Store<
PresentationState<ConfirmationDialogState<ButtonAction>>, PresentationAction<ButtonAction>
>
) -> some View {
self.actionSheet(store: store, state: { $0 }, action: { $0 })
}
/// Displays an 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.confirmationDialog(store:state:action:)' instead."
)
@available(macOS, unavailable)
@available(
tvOS,
introduced: 13,
deprecated: 100000,
message: "use 'View.confirmationDialog(store:state:action:)' instead."
)
@available(
watchOS,
introduced: 6,
deprecated: 100000,
message: "use 'View.confirmationDialog(store:state:action:)' instead."
)
public func actionSheet<State, Action, ButtonAction>(
store: Store<PresentationState<State>, PresentationAction<Action>>,
state toDestinationState: @escaping (_ state: State) -> ConfirmationDialogState<ButtonAction>?,
action fromDestinationAction: @escaping (_ alertAction: ButtonAction) -> Action
) -> some View {
self.presentation(
store: store, state: toDestinationState, action: fromDestinationAction
) { `self`, $item, _ in
let actionSheetState = store.withState { $0.wrappedValue.flatMap(toDestinationState) }
self.actionSheet(item: $item) { _ in
ActionSheet(actionSheetState!) { action in
if let action = action {
store.send(.presented(fromDestinationAction(action)))
} else {
store.send(.dismiss)
}
}
}
}
}
}