Przeglądaj źródła

Merge pull request #458 from CodeByMiniOrg/no-invisible-input

Change input fields to be masked instead of invisible in screenshots
Marion Barker 11 miesięcy temu
rodzic
commit
ae5917c585
1 zmienionych plików z 35 dodań i 27 usunięć
  1. 35 27
      LoopFollow/Helpers/Views/TogglableSecureInput.swift

+ 35 - 27
LoopFollow/Helpers/Views/TogglableSecureInput.swift

@@ -20,18 +20,22 @@ struct TogglableSecureInput: View {
             Group {
                 switch style {
                 case .singleLine:
-                    if isVisible {
-                        TextField(placeholder, text: $text)
-                            .multilineTextAlignment(.trailing)
-                            .textContentType(textContentType)
-                            .submitLabel(.done)
-                            .focused($isFocused)
-                    } else {
-                        SecureField(placeholder, text: $text)
-                            .multilineTextAlignment(.trailing)
-                            .textContentType(textContentType)
-                            .submitLabel(.done)
-                            .focused($isFocused)
+                    ZStack(alignment: .trailing) {
+                        if isVisible {
+                            TextField(placeholder, text: $text)
+                                .multilineTextAlignment(.trailing)
+                                .textContentType(textContentType)
+                                .submitLabel(.done)
+                                .focused($isFocused)
+                        } else {
+                            HStack {
+                                Spacer()
+                                Text(maskString)
+                                    .font(.body.monospaced())
+                                    .foregroundColor(.primary)
+                                    .allowsHitTesting(false)
+                            }
+                        }
                     }
 
                 case .multiLine:
@@ -53,15 +57,13 @@ struct TogglableSecureInput: View {
                             }
 
                         if !isVisible {
-                            Text(maskString)
-                                .font(.body.monospaced())
-                                .foregroundColor(.primary)
-                                .frame(maxWidth: .infinity,
-                                       maxHeight: .infinity,
-                                       alignment: .topLeading)
-                                .padding(.top, 8)
-                                .padding(.leading, 5)
-                                .allowsHitTesting(false)
+                            HStack {
+                                Spacer()
+                                Text(maskString)
+                                    .font(.body.monospaced())
+                                    .foregroundColor(.primary)
+                                    .allowsHitTesting(false)
+                            }
                         }
                     }
                     .frame(minHeight: 100)
@@ -80,13 +82,19 @@ struct TogglableSecureInput: View {
         }
         .contentShape(Rectangle())
         .onTapGesture {
-            if style == .multiLine && !isVisible {
+            if !isVisible {
                 isVisible = true
-                isMultilineFocused = true
-            } else if style == .singleLine {
-                isFocused = true
-            } else if style == .multiLine && isVisible {
-                isMultilineFocused = true
+                if style == .singleLine {
+                    isFocused = true
+                } else if style == .multiLine {
+                    isMultilineFocused = true
+                }
+            } else {
+                if style == .singleLine {
+                    isFocused = true
+                } else if style == .multiLine {
+                    isMultilineFocused = true
+                }
             }
         }
     }