Skip to content

Commit bd0f7d1

Browse files
committed
IOS-8946 Remove eye feature
1 parent 23cdd76 commit bd0f7d1

File tree

2 files changed

+23
-49
lines changed

2 files changed

+23
-49
lines changed

TangemSdk/TangemSdk/UI/Views/Common/FloatingTextField.swift

+1-11
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ struct FloatingTextField: View {
1616
var shouldBecomeFirstResponder: Bool = false
1717

1818
@EnvironmentObject private var style: TangemSdkStyle
19-
@State private var isSecured: Bool = true
2019

2120
@ViewBuilder
2221
private var textField: some View {
2322
FocusableTextField(
24-
isSecured: isSecured,
2523
shouldBecomeFirstResponder: shouldBecomeFirstResponder,
2624
text: text,
2725
onCommit: onCommit
@@ -44,11 +42,7 @@ struct FloatingTextField: View {
4442
.font(.system(size: 17))
4543
.frame(height: 17)
4644
}
47-
48-
Button(action: toggleSecured) {
49-
Image(systemName: isSecured ? "eye" : "eye.slash")
50-
.foregroundColor(.gray)
51-
}
45+
5246
}
5347

5448
Color(UIColor.opaqueSeparator)
@@ -57,10 +51,6 @@ struct FloatingTextField: View {
5751
.padding(.top, 20)
5852
.animation(Animation.easeInOut(duration: 0.1), value: text.wrappedValue)
5953
}
60-
61-
private func toggleSecured() {
62-
isSecured.toggle()
63-
}
6454
}
6555

6656

TangemSdk/TangemSdk/UI/Views/Common/FocusableTextField.swift

+22-38
Original file line numberDiff line numberDiff line change
@@ -11,73 +11,57 @@ import SwiftUI
1111
import Combine
1212

1313
struct FocusableTextField: View {
14-
let isSecured: Bool
1514
let shouldBecomeFirstResponder: Bool
1615
let text: Binding<String>
1716
var onCommit: () -> Void = {}
18-
17+
1918
@FocusState private var focusedField: Field?
2019
@StateObject private var model: FocusableTextFieldModel = .init()
21-
20+
2221
var body: some View {
23-
ZStack {
24-
if isSecured {
25-
SecureField("", text: text, onCommit: onCommit)
26-
.focused($focusedField, equals: .secure)
27-
} else {
28-
TextField("", text: text, onCommit: onCommit)
29-
.focused($focusedField, equals: .plain)
30-
}
31-
}
32-
.keyboardType(.default)
33-
.onAppear(perform: model.onAppear)
34-
.onChange(of: isSecured) { newValue in
35-
setFocus(for: newValue)
36-
}
37-
.onReceive(model.focusPublisher) { _ in
38-
if shouldBecomeFirstResponder {
39-
setFocus(for: isSecured)
22+
SecureField("", text: text, onCommit: onCommit)
23+
.textContentType(.oneTimeCode) // to prevent passwords suggestion. Tested on ios 15-18
24+
.focused($focusedField, equals: .secure)
25+
.keyboardType(.asciiCapable)
26+
.onAppear(perform: model.onAppear)
27+
.onReceive(model.focusPublisher) { _ in
28+
if shouldBecomeFirstResponder {
29+
focusedField = .secure
30+
}
4031
}
41-
}
4232
}
43-
44-
init(isSecured: Bool,
45-
shouldBecomeFirstResponder: Bool,
33+
34+
init(shouldBecomeFirstResponder: Bool,
4635
text: Binding<String>,
47-
onCommit: @escaping () -> Void = {}) {
48-
self.isSecured = isSecured
36+
onCommit: @escaping () -> Void = {}
37+
) {
4938
self.shouldBecomeFirstResponder = shouldBecomeFirstResponder
5039
self.text = text
5140
self.onCommit = onCommit
5241
}
53-
54-
private func setFocus(for value: Bool) {
55-
focusedField = value ? .secure : .plain
56-
}
5742
}
5843

5944

6045
private extension FocusableTextField {
6146
enum Field: Hashable {
6247
case secure
63-
case plain
6448
}
6549
}
6650

6751
fileprivate class FocusableTextFieldModel: ObservableObject {
6852
var focusPublisher: PassthroughSubject<Void, Never> = .init()
69-
53+
7054
private var appearPublisher: CurrentValueSubject<Bool, Never> = .init(false)
7155
private var activePublisher: CurrentValueSubject<Bool, Never> = .init(UIApplication.shared.isActive)
7256
private var bag: Set<AnyCancellable> = .init()
73-
57+
7458
private var becomeActivePublisher: AnyPublisher<Void, Never> {
7559
NotificationCenter.default
7660
.publisher(for: UIApplication.didBecomeActiveNotification)
7761
.map { _ in () }
7862
.eraseToAnyPublisher()
7963
}
80-
64+
8165
/// This is the minimum allowable delay, calculated empirically for all iOS versions prior 16.
8266
private var appearDelay: Int {
8367
if #available(iOS 16.0, *) {
@@ -86,22 +70,22 @@ fileprivate class FocusableTextFieldModel: ObservableObject {
8670
return 500
8771
}
8872
}
89-
73+
9074
init() {
9175
bind()
9276
}
93-
77+
9478
func onAppear() {
9579
appearPublisher.send(true)
9680
}
97-
81+
9882
private func bind() {
9983
becomeActivePublisher
10084
.sink { [weak self] _ in
10185
self?.activePublisher.send(true)
10286
}
10387
.store(in: &bag)
104-
88+
10589
appearPublisher
10690
.filter { $0 }
10791
.delay(for: .milliseconds(appearDelay), scheduler: DispatchQueue.main)

0 commit comments

Comments
 (0)