Skip to content

Commit dda8229

Browse files
committed
fix: textfield backspace not working
1 parent 87ac947 commit dda8229

File tree

8 files changed

+243
-171
lines changed

8 files changed

+243
-171
lines changed

samples/auth-swiftui/AuthSwiftUIExample/Views/Email/EmailResetPasswordView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ struct EmailResetPasswordView: View {
8888
onSendResetLinkClick: {},
8989
onGoToSignUp: {},
9090
onGoToSignIn: {},
91-
onGoToResetPassword: {},
92-
navigator: Navigator()
91+
onGoToResetPassword: {}
9392
))
9493
.safeAreaPadding()
9594
}

samples/auth-swiftui/AuthSwiftUIExample/Views/Email/EmailSignInView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ struct EmailSignInView: View {
8888
onSendResetLinkClick: {},
8989
onGoToSignUp: {},
9090
onGoToSignIn: {},
91-
onGoToResetPassword: {},
92-
navigator: Navigator()
91+
onGoToResetPassword: {}
9392
))
9493
.safeAreaPadding()
9594
}

samples/auth-swiftui/AuthSwiftUIExample/Views/Email/EmailSignUpView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ struct EmailSignUpView: View {
8989
onSendResetLinkClick: {},
9090
onGoToSignUp: {},
9191
onGoToSignIn: {},
92-
onGoToResetPassword: {},
93-
navigator: Navigator()
92+
onGoToResetPassword: {}
9493
))
9594
.safeAreaPadding()
9695
}

samples/auth-swiftui/AuthSwiftUIExample/Views/FirebaseAuthViewInternal.swift

Lines changed: 53 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,20 @@ struct EmailAuthContentState {
5757
var onGoToSignUp: () -> Void
5858
var onGoToSignIn: () -> Void
5959
var onGoToResetPassword: () -> Void
60-
var navigator: Navigator
6160
}
6261

6362
struct PhoneAuthContentState {
6463
var isLoading: Bool
6564
var error: String?
6665
var phoneNumber: Binding<String>
67-
var selectedCountry: CountryData
68-
var onCountrySelected: (CountryData) -> Void
69-
var onSendCodeClick: () -> Void
66+
var selectedCountry: Binding<CountryData>
7067
var verificationCode: Binding<String>
71-
var onVerificationCodeChange: (String) -> Void
72-
var onVerifyCodeClick: () -> Void
7368
var fullPhoneNumber: String
74-
var onResendCodeClick: () -> Void
7569
var resendTimer: Int
70+
var onSendCodeClick: () -> Void
71+
var onVerifyCodeClick: () -> Void
72+
var onResendCodeClick: () -> Void
7673
var onChangeNumberClick: () -> Void
77-
var navigator: Navigator
7874
}
7975

8076
@Observable
@@ -121,7 +117,7 @@ struct FirebaseAuthViewInternal: View {
121117
var body: some View {
122118
NavigationStack(path: $navigator.routes) {
123119
authMethodPicker
124-
120+
.navigationTitle("Authentication")
125121
.navigationBarTitleDisplayMode(.large)
126122
.navigationDestination(for: Route.self) { route in
127123
switch route {
@@ -152,6 +148,43 @@ struct FirebaseAuthViewInternal: View {
152148
.interactiveDismissDisabled(interactiveDismissDisabled)
153149
}
154150

151+
@ViewBuilder
152+
var authMethodPicker: some View {
153+
VStack(spacing: 36) {
154+
Image(.firebaseAuthLogo)
155+
GeometryReader { proxy in
156+
AuthMethodPicker { selectedProvider in
157+
switch selectedProvider {
158+
case .email:
159+
navigator.push(.emailAuth(.signIn))
160+
case .phone:
161+
navigator.push(.phoneAuth(.enterPhoneNumber))
162+
case .google:
163+
break
164+
case .facebook:
165+
break
166+
}
167+
}
168+
.padding(.horizontal, proxy.size.width * 0.18)
169+
}
170+
tosAndPPFooter
171+
.padding(.horizontal, 16)
172+
}
173+
.padding(.top, 24)
174+
.frame(maxWidth: .infinity, maxHeight: .infinity)
175+
}
176+
177+
@ViewBuilder
178+
var tosAndPPFooter: some View {
179+
AnnotatedString(
180+
fullText: "By continuing, you accept our Terms of Service and Privacy Policy.",
181+
links: [
182+
("Terms of Service", "https://example.com/terms"),
183+
("Privacy Policy", "https://example.com/privacy")
184+
]
185+
)
186+
}
187+
155188
// MARK: - State Creation
156189

157190
private func createEmailAuthState() -> EmailAuthContentState {
@@ -167,18 +200,14 @@ struct FirebaseAuthViewInternal: View {
167200
onSignUpClick: handleEmailSignUp,
168201
onSendResetLinkClick: handleSendResetLink,
169202
onGoToSignUp: {
170-
clearEmailForm()
171-
navigator.push(.emailAuth(.signUp))
203+
handleEmailAuthNavigation(route: .emailAuth(.signUp))
172204
},
173205
onGoToSignIn: {
174-
clearEmailForm()
175-
navigator.push(.emailAuth(.signIn))
206+
handleEmailAuthNavigation(route: .emailAuth(.signIn))
176207
},
177208
onGoToResetPassword: {
178-
clearEmailForm()
179-
navigator.push(.emailAuth(.resetPassword))
180-
},
181-
navigator: navigator
209+
handleEmailAuthNavigation(route: .emailAuth(.resetPassword))
210+
}
182211
)
183212
}
184213

@@ -187,34 +216,28 @@ struct FirebaseAuthViewInternal: View {
187216
isLoading: phoneIsLoading,
188217
error: phoneError,
189218
phoneNumber: $phoneNumber,
190-
selectedCountry: selectedCountry,
191-
onCountrySelected: { country in
192-
selectedCountry = country
193-
},
194-
onSendCodeClick: handleSendCode,
219+
selectedCountry: $selectedCountry,
195220
verificationCode: $verificationCode,
196-
onVerificationCodeChange: { code in
197-
verificationCode = code
198-
},
199-
onVerifyCodeClick: handleVerifyCode,
200221
fullPhoneNumber: "\(selectedCountry.dialCode) \(phoneNumber)",
201-
onResendCodeClick: handleResendCode,
202222
resendTimer: resendTimer,
223+
onSendCodeClick: handleSendCode,
224+
onVerifyCodeClick: handleVerifyCode,
225+
onResendCodeClick: handleResendCode,
203226
onChangeNumberClick: {
204227
verificationCode = ""
205228
navigator.pop()
206-
},
207-
navigator: navigator
229+
}
208230
)
209231
}
210232

211233
// MARK: - Email Auth Handlers
212234

213-
private func clearEmailForm() {
235+
private func handleEmailAuthNavigation(route: Route) {
214236
email = ""
215237
password = ""
216238
confirmPassword = ""
217239
displayName = ""
240+
navigator.push(route)
218241
}
219242

220243
private func handleEmailSignIn() {
@@ -243,42 +266,6 @@ struct FirebaseAuthViewInternal: View {
243266
private func handleResendCode() {
244267
// TODO: Implement resend code logic
245268
}
246-
247-
@ViewBuilder
248-
var authMethodPicker: some View {
249-
VStack(spacing: 36) {
250-
Image(.firebaseAuthLogo)
251-
GeometryReader { proxy in
252-
AuthMethodPicker { selectedProvider in
253-
switch selectedProvider {
254-
case .email:
255-
navigator.push(.emailAuth(.signIn))
256-
case .phone:
257-
navigator.push(.phoneAuth(.enterPhoneNumber))
258-
case .google:
259-
break
260-
case .facebook:
261-
break
262-
}
263-
}
264-
.padding(.horizontal, proxy.size.width * 0.18)
265-
}
266-
tosAndPPFooter
267-
}
268-
.padding(.top, 24)
269-
.frame(maxWidth: .infinity, maxHeight: .infinity)
270-
}
271-
272-
@ViewBuilder
273-
var tosAndPPFooter: some View {
274-
AnnotatedString(
275-
fullText: "By continuing, you accept our Terms of Service and Privacy Policy.",
276-
links: [
277-
("Terms of Service", "https://example.com/terms"),
278-
("Privacy Policy", "https://example.com/privacy")
279-
]
280-
)
281-
}
282269
}
283270

284271
#Preview {

samples/auth-swiftui/AuthSwiftUIExample/Views/Phone/CountrySelector.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import SwiftUI
99

1010
struct CountrySelector: View {
11-
let selectedCountry: CountryData
12-
let onCountrySelected: (CountryData) -> Void
11+
@Binding var selectedCountry: CountryData
1312
var enabled: Bool = true
1413
var allowedCountries: Set<String>? = nil
1514

@@ -43,7 +42,7 @@ struct CountrySelector: View {
4342
Menu {
4443
ForEach(filteredCountries, id: \.code) { country in
4544
Button {
46-
onCountrySelected(country)
45+
selectedCountry = country
4746
} label: {
4847
Text("\(country.flag) \(country.name) (\(country.dialCode))")
4948
}
@@ -66,7 +65,6 @@ struct CountrySelector: View {
6665

6766
#Preview {
6867
CountrySelector(
69-
selectedCountry: .default,
70-
onCountrySelected: { _ in }
68+
selectedCountry: .constant(.default)
7169
)
7270
}

samples/auth-swiftui/AuthSwiftUIExample/Views/Phone/EnterPhoneNumberView.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ struct EnterPhoneNumberView: View {
2929
) {
3030
CountrySelector(
3131
selectedCountry: state.selectedCountry,
32-
onCountrySelected: state.onCountrySelected,
3332
enabled: !state.isLoading
3433
)
3534
}
@@ -67,17 +66,14 @@ struct EnterPhoneNumberView: View {
6766
isLoading: false,
6867
error: nil,
6968
phoneNumber: .constant(""),
70-
selectedCountry: .default,
71-
onCountrySelected: { _ in },
72-
onSendCodeClick: {},
69+
selectedCountry: .constant(.default),
7370
verificationCode: .constant(""),
74-
onVerificationCodeChange: { _ in },
75-
onVerifyCodeClick: {},
7671
fullPhoneNumber: "+1 ",
77-
onResendCodeClick: {},
7872
resendTimer: 0,
79-
onChangeNumberClick: {},
80-
navigator: Navigator()
73+
onSendCodeClick: {},
74+
onVerifyCodeClick: {},
75+
onResendCodeClick: {},
76+
onChangeNumberClick: {}
8177
))
8278
.safeAreaPadding()
8379
}

samples/auth-swiftui/AuthSwiftUIExample/Views/Phone/EnterVerificationCodeView.swift

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ struct EnterVerificationCodeView: View {
3434
VerificationCodeInputField(
3535
code: state.verificationCode,
3636
isError: state.error != nil,
37-
errorMessage: state.error,
38-
onCodeComplete: { _ in
39-
state.onVerifyCodeClick()
40-
},
41-
onCodeChange: { newCode in
42-
state.onVerificationCodeChange(newCode)
43-
}
37+
errorMessage: state.error
4438
)
4539

4640
Button {
@@ -88,17 +82,14 @@ struct EnterVerificationCodeView: View {
8882
isLoading: false,
8983
error: nil,
9084
phoneNumber: .constant(""),
91-
selectedCountry: .default,
92-
onCountrySelected: { _ in },
93-
onSendCodeClick: {},
85+
selectedCountry: .constant(.default),
9486
verificationCode: .constant(""),
95-
onVerificationCodeChange: { _ in },
96-
onVerifyCodeClick: {},
9787
fullPhoneNumber: "+1 5551234567",
98-
onResendCodeClick: {},
9988
resendTimer: 0,
100-
onChangeNumberClick: {},
101-
navigator: Navigator()
89+
onSendCodeClick: {},
90+
onVerifyCodeClick: {},
91+
onResendCodeClick: {},
92+
onChangeNumberClick: {}
10293
))
10394
.safeAreaPadding()
10495
}

0 commit comments

Comments
 (0)