Skip to content

Commit

Permalink
IOS-8946 Remove eye (#4537)
Browse files Browse the repository at this point in the history
Co-authored-by: Skibin Alexander <[email protected]>
  • Loading branch information
tureck1y and skibinalexander authored Jan 28, 2025
1 parent 44a70eb commit 682449d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 60 deletions.
20 changes: 20 additions & 0 deletions Modules/TangemUIUtils/Extensions/View+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// View+.swift
// TangemUIUtils
//
// Created by Alexander Osokin on 27/01/2025.
// Copyright © 2025 Tangem AG. All rights reserved.
//

import SwiftUI

public extension View {
@ViewBuilder
func writingToolsBehaviorDisabled() -> some View {
if #available(iOS 18.0, *) {
self.writingToolsBehavior(.disabled)
} else {
self
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SwiftUI
import TangemUIUtils

struct CustomPasswordTextField: View {
let placeholder: String
Expand All @@ -19,55 +20,29 @@ struct CustomPasswordTextField: View {
var onEditingChanged: (Bool) -> Void = { _ in }
var onCommit: () -> Void = {}

@State var isSecured: Bool = true

@ViewBuilder
var input: some View {
var body: some View {
FocusableTextField(
isSecured: isSecured,
shouldBecomeFirstResponder: shouldBecomeFirstResponder,
placeholder: placeholder,
text: password,
onEditingChanged: onEditingChanged,
onCommit: onCommit
)
}

var body: some View {
GeometryReader { geom in
HStack(spacing: 8) {
input
.autocapitalization(.none)
.transition(.opacity)
.foregroundColor(color)
.keyboardType(.default)
.disableAutocorrection(true)

Button(action: {
withAnimation {
isSecured.toggle()
}
}, label: {
Image(systemName: isSecured ? "eye" : "eye.slash")
.foregroundColor(color)
.frame(width: geom.size.height, height: geom.size.height, alignment: .center)
})
}
.padding(.leading, 16)
.background(backgroundColor)
.cornerRadius(10)
}
.frame(height: 48)
.transition(.opacity)
.foregroundColor(color)
.padding(.leading, 16)
.background(backgroundColor)
.cornerRadius(10)
}
}

private extension CustomPasswordTextField {
enum Field: Hashable {
case secure
case plain
}

struct FocusableTextField: View {
let isSecured: Bool
let shouldBecomeFirstResponder: Bool
let placeholder: String
let text: Binding<String>
Expand All @@ -77,38 +52,22 @@ private extension CustomPasswordTextField {
@FocusState private var focusedField: Field?

var body: some View {
ZStack {
if isSecured {
SecureField(
placeholder,
text: text,
onCommit: onCommit
)
.focused($focusedField, equals: .secure)
} else {
TextField(
placeholder,
text: text,
onEditingChanged: onEditingChanged,
onCommit: onCommit
)
.focused($focusedField, equals: .plain)
}
}
SecureField(
placeholder,
text: text,
onCommit: onCommit
)
.focused($focusedField, equals: .secure)
.keyboardType(.default)
.writingToolsBehaviorDisabled()
.autocorrectionDisabled()
.textInputAutocapitalization(.never)
.onAppear(perform: onAppear)
.onChange(of: isSecured) { newValue in
setFocus(for: newValue)
}
}

private func setFocus(for value: Bool) {
focusedField = value ? .secure : .plain
}

private func onAppear() {
if shouldBecomeFirstResponder {
setFocus(for: isSecured)
focusedField = .secure
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "0361bd4787f3145b3afcc7bd203c29ef4e0a3c37160873528f70bfa18b6bf202",
"originHash" : "22c702cc862cb218d8a01e7d3633b9f66d30e361560a011ec04ff7f541321999",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down

0 comments on commit 682449d

Please sign in to comment.