diff --git a/DuckDuckGo/AutofillLoginDetailsView.swift b/DuckDuckGo/AutofillLoginDetailsView.swift index ba9eee9654..1c6fd06be6 100644 --- a/DuckDuckGo/AutofillLoginDetailsView.swift +++ b/DuckDuckGo/AutofillLoginDetailsView.swift @@ -148,7 +148,10 @@ struct AutofillLoginDetailsView: View { actionTitle: UserText.autofillCopyPrompt(for: UserText.autofillLoginDetailsAddress), action: { viewModel.copyToPasteboard(.address) }, secondaryActionTitle: viewModel.websiteIsValidUrl ? UserText.autofillOpenWebsitePrompt : nil, - secondaryAction: viewModel.websiteIsValidUrl ? { viewModel.openUrl() } : nil) + secondaryAction: viewModel.websiteIsValidUrl ? { viewModel.openUrl() } : nil, + buttonImageName: "Globe-24", + buttonAccessibilityLabel: UserText.autofillOpenWebsitePrompt, + buttonAction: viewModel.websiteIsValidUrl ? { viewModel.openUrl() } : nil) } Section { @@ -321,9 +324,12 @@ struct AutofillLoginDetailsView: View { action: { viewModel.isPasswordHidden.toggle() }, secondaryActionTitle: UserText.autofillCopyPrompt(for: UserText.autofillLoginDetailsPassword), secondaryAction: { viewModel.copyToPasteboard(.password) }, - buttonImageName: "Copy-24", - buttonAccessibilityLabel: UserText.autofillCopyPrompt(for: UserText.autofillLoginDetailsPassword), - buttonAction: { viewModel.copyToPasteboard(.password) }) + buttonImageName: viewModel.isPasswordHidden ? "Eye-24" : "Eye-Closed-24", + buttonAccessibilityLabel: viewModel.isPasswordHidden ? UserText.autofillShowPassword : UserText.autofillHidePassword, + buttonAction: { viewModel.isPasswordHidden.toggle() }, + secondaryButtonImageName: "Copy-24", + secondaryButtonAccessibilityLabel: UserText.autofillCopyPrompt(for: UserText.autofillLoginDetailsPassword), + secondaryButtonAction: { viewModel.copyToPasteboard(.password) }) } @@ -427,6 +433,10 @@ private struct CopyableCell: View { var buttonAccessibilityLabel: String? var buttonAction: (() -> Void)? + var secondaryButtonImageName: String? + var secondaryButtonAccessibilityLabel: String? + var secondaryButtonAction: (() -> Void)? + var body: some View { ZStack { HStack { @@ -452,7 +462,11 @@ private struct CopyableCell: View { } .padding(EdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 8)) - Spacer(minLength: buttonImageName != nil ? Constants.textFieldImageSize : 8) + if secondaryButtonImageName != nil { + Spacer(minLength: Constants.textFieldImageSize * 2 + 8) + } else { + Spacer(minLength: buttonImageName != nil ? Constants.textFieldImageSize : 8) + } } .copyable(isSelected: selectedCell == id, menuTitle: actionTitle, @@ -466,7 +480,7 @@ private struct CopyableCell: View { if let buttonImageName = buttonImageName, let buttonAccessibilityLabel = buttonAccessibilityLabel { let differenceBetweenImageSizeAndTapAreaPerEdge = (Constants.textFieldTapSize - Constants.textFieldImageSize) / 2.0 - HStack(alignment: .center) { + HStack(alignment: .center, spacing: 0) { Spacer() Button { @@ -488,10 +502,39 @@ private struct CopyableCell: View { } } .buttonStyle(.plain) // Prevent taps from being forwarded to the container view - .background(BackgroundColor(isSelected: selectedCell == id).color) + // can't use .clear here or else both button padded area and container both respond to tap events + .background(BackgroundColor(isSelected: selectedCell == id).color.opacity(0)) .accessibilityLabel(buttonAccessibilityLabel) .contentShape(Rectangle()) .frame(width: Constants.textFieldTapSize, height: Constants.textFieldTapSize) + + if let secondaryButtonImageName = secondaryButtonImageName, + let secondaryButtonAccessibilityLabel = secondaryButtonAccessibilityLabel { + Button { + secondaryButtonAction?() + self.selectedCell = nil + } label: { + VStack(alignment: .trailing) { + Spacer() + HStack { + Spacer() + Image(secondaryButtonImageName) + .resizable() + .frame(width: Constants.textFieldImageSize, height: Constants.textFieldImageSize) + .foregroundColor(Color(UIColor.label).opacity(Constants.textFieldImageOpacity)) + .opacity(subtitle.isEmpty ? 0 : 1) + Spacer() + } + Spacer() + } + } + .buttonStyle(.plain) // Prevent taps from being forwarded to the container view + .background(BackgroundColor(isSelected: selectedCell == id).color.opacity(0)) + .accessibilityLabel(secondaryButtonAccessibilityLabel) + .contentShape(Rectangle()) + .frame(width: Constants.textFieldTapSize, height: Constants.textFieldTapSize) + } + } .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: -differenceBetweenImageSizeAndTapAreaPerEdge)) } @@ -594,8 +637,8 @@ private struct Constants { static let verticalPadding: CGFloat = 4 static let minRowHeight: CGFloat = 60 static let textFieldImageOpacity: CGFloat = 0.84 - static let textFieldImageSize: CGFloat = 20 - static let textFieldTapSize: CGFloat = 44 + static let textFieldImageSize: CGFloat = 24 + static let textFieldTapSize: CGFloat = 36 static let insets = EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16) } diff --git a/DuckDuckGo/PasswordHider.swift b/DuckDuckGo/PasswordHider.swift index 4a91618fe6..1849248f24 100644 --- a/DuckDuckGo/PasswordHider.swift +++ b/DuckDuckGo/PasswordHider.swift @@ -22,7 +22,7 @@ import Foundation struct PasswordHider { let password: String var hiddenPassword: String { - let maximumPasswordDisplayCount = 40 + let maximumPasswordDisplayCount = 22 let passwordCount = password.count > maximumPasswordDisplayCount ? maximumPasswordDisplayCount : password.count return String(repeating: "•", count: passwordCount) }