From cf89c4b0be79f27c2a29a1fdda188e167ab6a20a Mon Sep 17 00:00:00 2001 From: Russel Date: Tue, 4 Feb 2025 06:26:39 +0100 Subject: [PATCH 1/2] feat: add custom modifier for plain text field --- ios/PolkadotVault.xcodeproj/project.pbxproj | 4 ++ .../TextFields/PlainTextField.swift | 45 +++++++++++++++++++ .../TextFields/SecuredTextField.swift | 7 +-- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 ios/PolkadotVault/Components/TextFields/PlainTextField.swift diff --git a/ios/PolkadotVault.xcodeproj/project.pbxproj b/ios/PolkadotVault.xcodeproj/project.pbxproj index f61f3b7992..b9e327a4a8 100644 --- a/ios/PolkadotVault.xcodeproj/project.pbxproj +++ b/ios/PolkadotVault.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0C2F8C4D2D512C34003A9DA0 /* PlainTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C2F8C4C2D512C34003A9DA0 /* PlainTextField.swift */; }; 2D48F35127609CDE004B27BE /* HistoryCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D48F35027609CDE004B27BE /* HistoryCard.swift */; }; 2D48F3532760A2D8004B27BE /* PrimaryFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D48F3522760A2D8004B27BE /* PrimaryFont.swift */; }; 2D48F3D2277A0AB2004B27BE /* HistoryCardExtended.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D48F3D1277A0AB2004B27BE /* HistoryCardExtended.swift */; }; @@ -427,6 +428,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0C2F8C4C2D512C34003A9DA0 /* PlainTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlainTextField.swift; sourceTree = ""; }; 2D48F35027609CDE004B27BE /* HistoryCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryCard.swift; sourceTree = ""; }; 2D48F3522760A2D8004B27BE /* PrimaryFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryFont.swift; sourceTree = ""; }; 2D48F3D1277A0AB2004B27BE /* HistoryCardExtended.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryCardExtended.swift; sourceTree = ""; }; @@ -2273,6 +2275,7 @@ 6D932CE5292E0CE6008AD883 /* PrimaryTextField.swift */, 6DA08B8729ACFC230027CFCB /* InlineTextField.swift */, 6D850BE1292F85F200BA9017 /* SecuredTextField.swift */, + 0C2F8C4C2D512C34003A9DA0 /* PlainTextField.swift */, ); path = TextFields; sourceTree = ""; @@ -2656,6 +2659,7 @@ 6DF5E7A42923DD4400F2B5B4 /* Text+Markdown.swift in Sources */, 6D7DE0D42ACB178800BFAACA /* DatabaseVersionMediator.swift in Sources */, 6DDEF13228AE6039004CA2FD /* signer.udl in Sources */, + 0C2F8C4D2D512C34003A9DA0 /* PlainTextField.swift in Sources */, 6DF8316728F9BA4A00CB2BCE /* CapsuleButton.swift in Sources */, 6DCC572728D8C0490014278A /* BackupModal.swift in Sources */, 6DDD73732940471900F04CE7 /* Event+AdditionalValue.swift in Sources */, diff --git a/ios/PolkadotVault/Components/TextFields/PlainTextField.swift b/ios/PolkadotVault/Components/TextFields/PlainTextField.swift new file mode 100644 index 0000000000..9a42a4f2ad --- /dev/null +++ b/ios/PolkadotVault/Components/TextFields/PlainTextField.swift @@ -0,0 +1,45 @@ +// +// SecuredTextField.swift +// Polkadot Vault +// +// Created by Ruslan Rezin on 03/02/2025. +// + +import SwiftUI + +struct PlainTextFieldStyle: ViewModifier { + let placeholder: String + let keyboardType: UIKeyboardType + @Binding var text: String + @Binding var isValid: Bool + + func body(content: Content) -> some View { + content + .foregroundColor(isValid ? .textAndIconsPrimary : .accentRed300) + .placeholder(placeholder, when: text.isEmpty) + .font(PrimaryFont.bodyL.font) + .autocapitalization(.none) + .disableAutocorrection(true) + .keyboardType(keyboardType) + .submitLabel(.return) + .frame(height: Heights.textFieldHeight) + } +} + +extension View { + func plainTextFieldStyle( + _ placeholder: String, + keyboardType: UIKeyboardType = .asciiCapable, + text: Binding, + isValid: Binding = Binding.constant(true) + ) -> some View { + modifier( + PlainTextFieldStyle( + placeholder: placeholder, + keyboardType: keyboardType, + text: text, + isValid: isValid + ) + ) + } +} diff --git a/ios/PolkadotVault/Components/TextFields/SecuredTextField.swift b/ios/PolkadotVault/Components/TextFields/SecuredTextField.swift index 8bc9d1aad3..52207893a3 100644 --- a/ios/PolkadotVault/Components/TextFields/SecuredTextField.swift +++ b/ios/PolkadotVault/Components/TextFields/SecuredTextField.swift @@ -22,7 +22,7 @@ struct SecurePrimaryTextField: View { var onCommit: (() -> Void) = {} var body: some View { - ZStack(alignment: .trailing) { + HStack(alignment: .center, spacing: Spacing.minimal) { ZStack { SecureField("", text: $text, onCommit: { onCommit() @@ -39,7 +39,7 @@ struct SecurePrimaryTextField: View { .focused($focusedField, equals: .plain) .opacity(isSecured ? 0 : 1) } - .primaryTextFieldStyle(placeholder, text: $text, isValid: $isValid) + .plainTextFieldStyle(placeholder, text: $text, isValid: $isValid) .onChange(of: text) { _ in isValid = true } @@ -50,9 +50,10 @@ struct SecurePrimaryTextField: View { } ) { Image(isSecured ? .showPassword : .hidePassword) - .padding(.trailing, Spacing.medium) .foregroundColor(.textAndIconsTertiary) } } + .padding(.horizontal, Spacing.medium) + .containerBackground(CornerRadius.small, state: isValid ? .standard : .error) } } From 18c384e3848b8d1b3fdee069e27be8dde4304411 Mon Sep 17 00:00:00 2001 From: Russel Date: Wed, 5 Feb 2025 11:27:41 +0100 Subject: [PATCH 2/2] refactor --- ios/PolkadotVault/Components/TextFields/PlainTextField.swift | 2 +- .../Components/TextFields/SecuredTextField.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/PolkadotVault/Components/TextFields/PlainTextField.swift b/ios/PolkadotVault/Components/TextFields/PlainTextField.swift index 9a42a4f2ad..922528479f 100644 --- a/ios/PolkadotVault/Components/TextFields/PlainTextField.swift +++ b/ios/PolkadotVault/Components/TextFields/PlainTextField.swift @@ -1,5 +1,5 @@ // -// SecuredTextField.swift +// PlainTextField.swift // Polkadot Vault // // Created by Ruslan Rezin on 03/02/2025. diff --git a/ios/PolkadotVault/Components/TextFields/SecuredTextField.swift b/ios/PolkadotVault/Components/TextFields/SecuredTextField.swift index 52207893a3..ed9ca99614 100644 --- a/ios/PolkadotVault/Components/TextFields/SecuredTextField.swift +++ b/ios/PolkadotVault/Components/TextFields/SecuredTextField.swift @@ -22,7 +22,7 @@ struct SecurePrimaryTextField: View { var onCommit: (() -> Void) = {} var body: some View { - HStack(alignment: .center, spacing: Spacing.minimal) { + HStack(alignment: .center, spacing: Spacing.minimal) { ZStack { SecureField("", text: $text, onCommit: { onCommit() @@ -39,7 +39,7 @@ struct SecurePrimaryTextField: View { .focused($focusedField, equals: .plain) .opacity(isSecured ? 0 : 1) } - .plainTextFieldStyle(placeholder, text: $text, isValid: $isValid) + .plainTextFieldStyle(placeholder, text: $text, isValid: $isValid) .onChange(of: text) { _ in isValid = true }