forked from mlemgroup/mlem
-
Notifications
You must be signed in to change notification settings - Fork 0
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
ee83e22
commit 497bdd2
Showing
24 changed files
with
343 additions
and
279 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 was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
Mlem/Extensions/View Modifiers/View+DestructiveConfirmation.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,60 @@ | ||
// | ||
// View+DestructiveConfirmation.swift | ||
// Mlem | ||
// | ||
// Created by Eric Andrews on 2023-09-06. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct DestructiveConfirmation: ViewModifier { | ||
let confirmationMenuFunction: StandardMenuFunction? | ||
@Binding var isPresentingConfirmDestructive: Bool | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.confirmationDialog("Destructive Action Confirmation", isPresented: $isPresentingConfirmDestructive) { | ||
if let destructiveCallback = confirmationMenuFunction?.callback { | ||
Button("Yes", role: .destructive) { | ||
Task { | ||
destructiveCallback() | ||
} | ||
} | ||
} | ||
} message: { | ||
if let destructivePrompt = confirmationMenuFunction?.destructiveActionPrompt { | ||
Text(destructivePrompt) | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
/// View modifier to attach a destructive action confirmation. | ||
/// | ||
/// To use, add the following to the view in which you use it: | ||
/// | ||
/// \@State private var isPresentingConfirmDestructive: Bool = false | ||
/// \@State private var confirmationMenuFunction: StandardMenuFunction? | ||
/// | ||
/// func confirmDestructive(destructiveFunction: StandardMenuFunction) { | ||
/// confirmationMenuFunction = destructiveFunction | ||
/// isPresentingConfirmDestructive = true | ||
/// } | ||
/// | ||
/// Calling confirmDestructive with a StandardMenuFunction will then trigger a confirmation. | ||
/// | ||
/// - Parameters: | ||
/// - isPresentingConfirmDestructive: binding Bool to toggle the confirmation presentation | ||
/// - confirmationMenuFunction: menu function to confirm | ||
func destructiveConfirmation( | ||
isPresentingConfirmDestructive: Binding<Bool>, | ||
confirmationMenuFunction: StandardMenuFunction? | ||
) -> some View { | ||
modifier(DestructiveConfirmation( | ||
confirmationMenuFunction: confirmationMenuFunction, | ||
isPresentingConfirmDestructive: isPresentingConfirmDestructive | ||
)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.