diff --git a/Packages/App/Sources/UILibrary/Theme/UI/Theme+Views.swift b/Packages/App/Sources/UILibrary/Theme/UI/Theme+Views.swift index 01e5b513..5ad7204d 100644 --- a/Packages/App/Sources/UILibrary/Theme/UI/Theme+Views.swift +++ b/Packages/App/Sources/UILibrary/Theme/UI/Theme+Views.swift @@ -215,7 +215,7 @@ public struct ThemeSecureField: View { } var fieldView: some View { - RevealingSecureField(title ?? "", text: $text, prompt: Text(placeholder), imageWidth: 30.0) { + RevealingSecureField(title ?? "", text: $text, prompt: Text(placeholder)) { ThemeImage(.hide) .foregroundStyle(Color.accentColor) } revealImage: { diff --git a/Packages/App/Sources/UILibrary/Views/UI/RevealingSecureField.swift b/Packages/App/Sources/UILibrary/Views/UI/RevealingSecureField.swift index f83e50cd..b7c7239a 100644 --- a/Packages/App/Sources/UILibrary/Views/UI/RevealingSecureField.swift +++ b/Packages/App/Sources/UILibrary/Views/UI/RevealingSecureField.swift @@ -33,8 +33,6 @@ public struct RevealingSecureField: View where ImageView: View { private var prompt: Text? - private let imageWidth: CGFloat - private let conceilImage: () -> ImageView private let revealImage: () -> ImageView @@ -46,7 +44,6 @@ public struct RevealingSecureField: View where ImageView: View { _ title: String, text: Binding, prompt: Text? = nil, - imageWidth: CGFloat, conceilImage: @escaping () -> ImageView, revealImage: @escaping () -> ImageView ) { @@ -55,34 +52,39 @@ public struct RevealingSecureField: View where ImageView: View { self.prompt = prompt self.conceilImage = conceilImage self.revealImage = revealImage - self.imageWidth = imageWidth } public var body: some View { - if isRevealed { - TextField(title, text: $text, prompt: prompt) - .overlay(alignment: .trailing) { - Button { - isRevealed.toggle() - } label: { - conceilImage() - } - .buttonStyle(.plain) - .padding(.trailing, -imageWidth) + HStack { + if isRevealed { + TextField(title, text: $text, prompt: prompt) + Button { + isRevealed.toggle() + } label: { + conceilImage() } - .padding(.trailing, imageWidth) - } else { - SecureField(title, text: $text, prompt: prompt) - .overlay(alignment: .trailing) { - Button { - isRevealed.toggle() - } label: { - revealImage() - } - .buttonStyle(.plain) - .padding(.trailing, -imageWidth) + .buttonStyle(.borderless) + } else { + SecureField(title, text: $text, prompt: prompt) + Button { + isRevealed.toggle() + } label: { + revealImage() } - .padding(.trailing, imageWidth) + .buttonStyle(.borderless) + } } } } + +#Preview { + Form { + TextField("text", text: .constant("plain-text")) + RevealingSecureField("secure", text: .constant("secure-text")) { + Image(systemName: "eye.slash") + } revealImage: { + Image(systemName: "eye") + } + } + .formStyle(.grouped) +}