Skip to content

Commit eb59b46

Browse files
authored
IOS-8946 Remove eye feature (#399)
1 parent 0371448 commit eb59b46

File tree

3 files changed

+37
-51
lines changed

3 files changed

+37
-51
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313
jobs:
1414
test:
1515
name: Test
16-
runs-on: macOS-latest
16+
runs-on: macos-15
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v2

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

+35-39
Original file line numberDiff line numberDiff line change
@@ -11,73 +11,59 @@ 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+
.focused($focusedField, equals: .secure)
24+
.keyboardType(.default)
25+
.writingToolsBehaviorDisabled()
26+
.autocorrectionDisabled()
27+
.textInputAutocapitalization(.never)
28+
.onAppear(perform: model.onAppear)
29+
.onReceive(model.focusPublisher) { _ in
30+
if shouldBecomeFirstResponder {
31+
focusedField = .secure
32+
}
4033
}
41-
}
4234
}
43-
44-
init(isSecured: Bool,
45-
shouldBecomeFirstResponder: Bool,
35+
36+
init(shouldBecomeFirstResponder: Bool,
4637
text: Binding<String>,
47-
onCommit: @escaping () -> Void = {}) {
48-
self.isSecured = isSecured
38+
onCommit: @escaping () -> Void = {}
39+
) {
4940
self.shouldBecomeFirstResponder = shouldBecomeFirstResponder
5041
self.text = text
5142
self.onCommit = onCommit
5243
}
53-
54-
private func setFocus(for value: Bool) {
55-
focusedField = value ? .secure : .plain
56-
}
5744
}
5845

5946

6047
private extension FocusableTextField {
6148
enum Field: Hashable {
6249
case secure
63-
case plain
6450
}
6551
}
6652

6753
fileprivate class FocusableTextFieldModel: ObservableObject {
6854
var focusPublisher: PassthroughSubject<Void, Never> = .init()
69-
55+
7056
private var appearPublisher: CurrentValueSubject<Bool, Never> = .init(false)
7157
private var activePublisher: CurrentValueSubject<Bool, Never> = .init(UIApplication.shared.isActive)
7258
private var bag: Set<AnyCancellable> = .init()
73-
59+
7460
private var becomeActivePublisher: AnyPublisher<Void, Never> {
7561
NotificationCenter.default
7662
.publisher(for: UIApplication.didBecomeActiveNotification)
7763
.map { _ in () }
7864
.eraseToAnyPublisher()
7965
}
80-
66+
8167
/// This is the minimum allowable delay, calculated empirically for all iOS versions prior 16.
8268
private var appearDelay: Int {
8369
if #available(iOS 16.0, *) {
@@ -86,22 +72,22 @@ fileprivate class FocusableTextFieldModel: ObservableObject {
8672
return 500
8773
}
8874
}
89-
75+
9076
init() {
9177
bind()
9278
}
93-
79+
9480
func onAppear() {
9581
appearPublisher.send(true)
9682
}
97-
83+
9884
private func bind() {
9985
becomeActivePublisher
10086
.sink { [weak self] _ in
10187
self?.activePublisher.send(true)
10288
}
10389
.store(in: &bag)
104-
90+
10591
appearPublisher
10692
.filter { $0 }
10793
.delay(for: .milliseconds(appearDelay), scheduler: DispatchQueue.main)
@@ -113,9 +99,19 @@ fileprivate class FocusableTextFieldModel: ObservableObject {
11399
}
114100
}
115101

116-
117102
fileprivate extension UIApplication {
118103
var isActive: Bool {
119104
applicationState == .active
120105
}
121106
}
107+
108+
fileprivate extension View {
109+
@ViewBuilder
110+
func writingToolsBehaviorDisabled() -> some View {
111+
if #available(iOS 18.0, *) {
112+
self.writingToolsBehavior(.disabled)
113+
} else {
114+
self
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)