From 5dffc41026d9187570ba07f8e25b0a9b7b26bbae Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 25 Jun 2024 09:46:09 +0200 Subject: [PATCH] Adds a show button for password fields --- PadelClub.xcodeproj/project.pbxproj | 18 +++++--- .../Views/Components/PasswordField.swift | 43 +++++++++++++++++++ PadelClub/Views/User/ChangePasswordView.swift | 6 +-- PadelClub/Views/User/LoginView.swift | 2 +- PadelClub/Views/User/UserCreationView.swift | 4 +- 5 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 PadelClub/Views/Components/PasswordField.swift diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 755e481..be6ed30 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -46,6 +46,7 @@ C4B3A1552C2581DA0078EAA8 /* Patcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B3A1542C2581DA0078EAA8 /* Patcher.swift */; }; C4EC6F572BE92CAC000CEAB4 /* local.plist in Resources */ = {isa = PBXBuildFile; fileRef = C4EC6F562BE92CAC000CEAB4 /* local.plist */; }; C4EC6F592BE92D88000CEAB4 /* PListReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4EC6F582BE92D88000CEAB4 /* PListReader.swift */; }; + C4FC2E272C2AABC90021F3BF /* PasswordField.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4FC2E262C2AABC90021F3BF /* PasswordField.swift */; }; FF025AD82BD0C10F00A86CF8 /* TeamHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF025AD72BD0C10F00A86CF8 /* TeamHeaderView.swift */; }; FF025ADB2BD0C2D000A86CF8 /* MatchTeamDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF025ADA2BD0C2D000A86CF8 /* MatchTeamDetailView.swift */; }; FF025ADD2BD0C94300A86CF8 /* FooterButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF025ADC2BD0C94300A86CF8 /* FooterButtonView.swift */; }; @@ -333,6 +334,7 @@ C4B3A1542C2581DA0078EAA8 /* Patcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Patcher.swift; sourceTree = ""; }; C4EC6F562BE92CAC000CEAB4 /* local.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = local.plist; sourceTree = ""; }; C4EC6F582BE92D88000CEAB4 /* PListReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PListReader.swift; sourceTree = ""; }; + C4FC2E262C2AABC90021F3BF /* PasswordField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordField.swift; sourceTree = ""; }; FF025AD72BD0C10F00A86CF8 /* TeamHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeamHeaderView.swift; sourceTree = ""; }; FF025ADA2BD0C2D000A86CF8 /* MatchTeamDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchTeamDetailView.swift; sourceTree = ""; }; FF025ADC2BD0C94300A86CF8 /* FooterButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterButtonView.swift; sourceTree = ""; }; @@ -780,15 +782,16 @@ C4A47DA02B7D0BD800ADC637 /* Components */ = { isa = PBXGroup; children = ( - C4A47D9E2B7D0BCE00ADC637 /* StepperView.swift */, - FF5DA1942BB927E800A33061 /* GenericDestinationPickerView.swift */, - FF6EC8F62B94773100EA7F5A /* RowButtonView.swift */, - FF025ADC2BD0C94300A86CF8 /* FooterButtonView.swift */, - FFBF065D2BBD8040009D6715 /* MatchListView.swift */, - FF967CF72BAEDF0000A9A3BD /* Labels.swift */, - FFC91AF82BD6A09100B29808 /* FortuneWheelView.swift */, FF1DF49A2BD8D23900822FA0 /* BarButtonView.swift */, FFF03C932BD91D0C00B516FC /* ButtonValidateView.swift */, + FF025ADC2BD0C94300A86CF8 /* FooterButtonView.swift */, + FFC91AF82BD6A09100B29808 /* FortuneWheelView.swift */, + FF5DA1942BB927E800A33061 /* GenericDestinationPickerView.swift */, + FF967CF72BAEDF0000A9A3BD /* Labels.swift */, + FFBF065D2BBD8040009D6715 /* MatchListView.swift */, + C4FC2E262C2AABC90021F3BF /* PasswordField.swift */, + FF6EC8F62B94773100EA7F5A /* RowButtonView.swift */, + C4A47D9E2B7D0BCE00ADC637 /* StepperView.swift */, ); path = Components; sourceTree = ""; @@ -1579,6 +1582,7 @@ FF967CF62BAED51600A9A3BD /* TournamentRunningView.swift in Sources */, FF8F264D2BAE0B4100650388 /* TournamentDatePickerView.swift in Sources */, FFF116E32BD2AF4800A33B06 /* CourtAvailabilitySettingsView.swift in Sources */, + C4FC2E272C2AABC90021F3BF /* PasswordField.swift in Sources */, FF967D042BAEF1C300A9A3BD /* MatchRowView.swift in Sources */, C44B79112BBDA63A00906534 /* Locale+Extensions.swift in Sources */, FF1F4B742BFA00FC000B4573 /* HtmlService.swift in Sources */, diff --git a/PadelClub/Views/Components/PasswordField.swift b/PadelClub/Views/Components/PasswordField.swift new file mode 100644 index 0000000..030e443 --- /dev/null +++ b/PadelClub/Views/Components/PasswordField.swift @@ -0,0 +1,43 @@ +// +// PasswordView.swift +// PadelClub +// +// Created by Laurent Morvillier on 25/06/2024. +// + +import SwiftUI + +struct PasswordField: View { + + var label: String + @Binding var password: String + + @State var visible: Bool = false + + init(_ label: String, text: Binding) { + self.label = label + self._password = text + } + + var body: some View { + + HStack { + + if self.visible { + TextField(self.label, text: self.$password) + } else { + SecureField(self.label, text: self.$password) + } + Spacer() + Button { + self.visible.toggle() + } label: { + let image = self.visible ? "eye.slash" : "eye" + Image(systemName: image) + } + + } + + } + +} diff --git a/PadelClub/Views/User/ChangePasswordView.swift b/PadelClub/Views/User/ChangePasswordView.swift index 4f3e210..8e9b2e7 100644 --- a/PadelClub/Views/User/ChangePasswordView.swift +++ b/PadelClub/Views/User/ChangePasswordView.swift @@ -21,9 +21,9 @@ struct ChangePasswordView: View { Form { - SecureField("Old password", text: self.$oldPassword) - SecureField("Password", text: self.$password1) - SecureField("Password again", text: self.$password2) + PasswordField("Old password", text: self.$oldPassword) + PasswordField("Password", text: self.$password1) + PasswordField("Password again", text: self.$password2) Section { Button(action: { diff --git a/PadelClub/Views/User/LoginView.swift b/PadelClub/Views/User/LoginView.swift index 8a52e49..cbfdf6a 100644 --- a/PadelClub/Views/User/LoginView.swift +++ b/PadelClub/Views/User/LoginView.swift @@ -113,7 +113,7 @@ struct LoginView: View { .onSubmit(of: .text) { focusedField = .password } - SecureField("Mot de passe", text: self.$password) + PasswordField("Mot de passe", text: self.$password) .textContentType(.init(rawValue: "")) .submitLabel(.send) .onSubmit(of: .text) { diff --git a/PadelClub/Views/User/UserCreationView.swift b/PadelClub/Views/User/UserCreationView.swift index d9fb492..69074d8 100644 --- a/PadelClub/Views/User/UserCreationView.swift +++ b/PadelClub/Views/User/UserCreationView.swift @@ -82,7 +82,7 @@ struct UserCreationFormView: View { } Section { - SecureField("Mot de passe", text: self.$password1) + PasswordField("Mot de passe", text: self.$password1) .focused($focusedField, equals: .password) .textContentType(.init(rawValue: "")) .keyboardType(.asciiCapable) @@ -92,7 +92,7 @@ struct UserCreationFormView: View { focusedField = .confirmPassword } - SecureField("Confirmez le mot de passe", text: self.$password2) + PasswordField("Confirmez le mot de passe", text: self.$password2) .focused($focusedField, equals: .confirmPassword) .textContentType(.init(rawValue: "")) .keyboardType(.asciiCapable)