-
Notifications
You must be signed in to change notification settings - Fork 14
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 #1643 from planetary-social/delete-account-textfield
Add Delete confirmation before deleting account
- Loading branch information
Showing
11 changed files
with
350 additions
and
25 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
20 changes: 20 additions & 0 deletions
20
Nos/Assets/Colors.xcassets/action-sheet-bg.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0x2C", | ||
"green" : "0x26", | ||
"red" : "0x28" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Nos/Assets/Colors.xcassets/action-sheet-divider.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0x6D", | ||
"green" : "0x63", | ||
"red" : "0x66" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Nos/Assets/Colors.xcassets/action-sheet-overlay.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0x19", | ||
"green" : "0x09", | ||
"red" : "0x0E" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Nos/Assets/Colors.xcassets/action-sheet-textfield-bg-bright.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0x1A", | ||
"green" : "0x16", | ||
"red" : "0x17" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Nos/Assets/Colors.xcassets/action-sheet-textfield-bg-dim.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0x21", | ||
"green" : "0x1D", | ||
"red" : "0x1E" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Nos/Assets/Colors.xcassets/action-sheet-textfield-placeholder.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0x6D", | ||
"green" : "0x63", | ||
"red" : "0x66" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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,28 @@ | ||
import SwiftUI | ||
|
||
/// Displays a placeholder text when required. | ||
/// - Parameters: | ||
/// - show: A Boolean indicating whether to show the placeholder. | ||
/// - placeholder: The text to display as the placeholder. | ||
struct PlaceholderStyle: ViewModifier { | ||
var show: Bool | ||
var placeholder: String | ||
|
||
/// Displays the placeholder text if `show` is true, overlaying it | ||
/// on the content view. | ||
func body(content: Content) -> some View { | ||
ZStack(alignment: .leading) { | ||
if show { | ||
Text(placeholder) | ||
.foregroundColor(Color.actionSheetTextfieldPlaceholder) | ||
.padding(.leading, 9) | ||
.font(.headline) | ||
.fontWeight(.bold) | ||
} | ||
content | ||
.foregroundColor(Color.white) | ||
.font(.headline) | ||
.fontWeight(.bold) | ||
} | ||
} | ||
} |
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,130 @@ | ||
import SwiftUI | ||
|
||
/// This view displays a title and message, along with a text field | ||
/// for user confirmation. It provides buttons to cancel the action | ||
/// or proceed with the deletion (which is enabled only when the | ||
/// correct confirmation text is entered). | ||
/// - Parameters: | ||
/// - requiredText: The text that must be entered to confirm the deletion. | ||
/// - onDelete: A closure that is called when the delete button is confirmed. | ||
/// - onCancel: A closure that is called when the cancel button is selected. | ||
struct DeleteConfirmationView: View { | ||
@State private var confirmationText: String = "" | ||
|
||
var requiredText: String | ||
var onDelete: (() -> Void) | ||
var onCancel: (() -> Void) | ||
|
||
var isDeleteDisabled: Bool { | ||
confirmationText != requiredText | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: 0) { | ||
VStack(spacing: 0) { | ||
titleMessageView() | ||
|
||
confirmationTextField( | ||
confirmationText: $confirmationText, | ||
requiredText: requiredText | ||
) | ||
} | ||
.padding() | ||
|
||
Divider() | ||
.frame(height: 1) | ||
.background(Color.actionSheetDivider) | ||
|
||
actionButtonsView( | ||
isDeleteDisabled: isDeleteDisabled, | ||
onDelete: onDelete, | ||
onCancel: onCancel | ||
) | ||
} | ||
.background(Color.actionSheetBg) | ||
.cornerRadius(10) | ||
.frame(width: 302, height: 228) | ||
.shadow(color: Color.black.opacity(0.25), radius: 25, x: 0, y: 10) | ||
} | ||
|
||
/// Creates the title and message view for the delete confirmation. | ||
private func titleMessageView() -> some View { | ||
VStack(spacing: 0) { | ||
Text(String(localized: "deleteAccount")) | ||
.font(.headline) | ||
.fontWeight(.bold) | ||
.padding(.bottom, 10) | ||
.padding(.top, 18) | ||
|
||
Text(String(localized: "deleteAccountMessage")) | ||
.font(.footnote) | ||
.fixedSize(horizontal: false, vertical: true) | ||
.multilineTextAlignment(.center) | ||
.foregroundColor(.white) | ||
.padding(.horizontal) | ||
.padding(.bottom, 15) | ||
} | ||
} | ||
|
||
/// Creates the text field to confirm the user's input. | ||
/// - Parameters: | ||
/// - confirmationText: A binding to the user's input text. | ||
/// - requiredText: The text that must be entered for confirmation. | ||
/// - Returns: A `TextField` configured for confirming user's input. | ||
private func confirmationTextField(confirmationText: Binding<String>, requiredText: String) -> some View { | ||
let isTyping = !confirmationText.wrappedValue.isEmpty | ||
|
||
return TextField("", text: confirmationText) | ||
.foregroundColor(.white) | ||
.autocapitalization(.allCharacters) | ||
.padding(10) | ||
.cornerRadius(8) | ||
.overlay( | ||
RoundedRectangle(cornerRadius: 4) | ||
.stroke(isTyping ? .white : Color.actionSheetTextfieldPlaceholder, lineWidth: 1) | ||
) | ||
.modifier( | ||
PlaceholderStyle( | ||
show: confirmationText.wrappedValue.isEmpty, | ||
placeholder: String(localized: "typeDelete") | ||
) | ||
) | ||
.background(isTyping ? Color.actionSheetTextfieldBgBright : Color.actionSheetTextfieldBgDim) | ||
.padding(.horizontal, 22) | ||
.padding(.bottom, 5) | ||
} | ||
|
||
/// Creates the cancel and delete buttons. | ||
private func actionButtonsView( | ||
isDeleteDisabled: Bool, | ||
onDelete: @escaping () -> Void, | ||
onCancel: @escaping () -> Void | ||
) -> some View { | ||
HStack { | ||
Button(String(localized: "cancel")) { | ||
onCancel() | ||
} | ||
.frame(maxWidth: .infinity) | ||
.foregroundColor(.blue) | ||
|
||
Divider() | ||
.frame(width: 1, height: 50) | ||
.background(Color.actionSheetDivider) | ||
|
||
Button(String(localized: "delete")) { | ||
onDelete() | ||
} | ||
.frame(maxWidth: .infinity) | ||
.foregroundColor(isDeleteDisabled ? Color.actionSheetDivider : .red) | ||
.disabled(isDeleteDisabled) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
DeleteConfirmationView( | ||
requiredText: String(localized: "deleteAccount").uppercased(), | ||
onDelete: {}, | ||
onCancel: {} | ||
) | ||
} |
Oops, something went wrong.