Skip to content

Commit 4066b13

Browse files
committed
use @bindable for binding observable objects
1 parent 54d9b33 commit 4066b13

4 files changed

Lines changed: 9 additions & 29 deletions

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerView.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extension AuthPickerView: View {
9292

9393
@ViewBuilder
9494
var authPickerViewInternal: some View {
95+
@Bindable var authService = authService
9596
VStack {
9697
if authService.authenticationState == .unauthenticated {
9798
authMethodPicker
@@ -101,10 +102,7 @@ extension AuthPickerView: View {
101102
}
102103
}
103104
.errorAlert(
104-
error: Binding(
105-
get: { authService.currentError },
106-
set: { authService.currentError = $0 }
107-
),
105+
error: $authService.currentError,
108106
okButtonLabel: authService.string.okButtonLabel
109107
)
110108
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/MFAManagementView.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ public struct MFAManagementView {
2727
@State private var enrolledFactors: [MultiFactorInfo] = []
2828
@State private var isLoading = false
2929

30-
// Present password prompt when required for reauthentication
31-
private var isShowingPasswordPrompt: Binding<Bool> {
32-
Binding(
33-
get: { authService.passwordPrompt.isPromptingPassword },
34-
set: { authService.passwordPrompt.isPromptingPassword = $0 }
35-
)
36-
}
37-
3830
public init() {}
3931

4032
private func loadEnrolledFactors() {
@@ -63,6 +55,7 @@ public struct MFAManagementView {
6355

6456
extension MFAManagementView: View {
6557
public var body: some View {
58+
@Bindable var passwordPrompt = authService.passwordPrompt
6659
VStack(spacing: 20) {
6760
// Title section
6861
VStack {
@@ -140,7 +133,8 @@ extension MFAManagementView: View {
140133
.onAppear {
141134
loadEnrolledFactors()
142135
}
143-
.sheet(isPresented: isShowingPasswordPrompt) {
136+
// Present password prompt when required for reauthentication
137+
.sheet(isPresented: $passwordPrompt.isPromptingPassword) {
144138
PasswordPromptSheet(coordinator: authService.passwordPrompt)
145139
}
146140
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,8 @@ public struct SignedInView {
3232
}
3333

3434
extension SignedInView: View {
35-
private var isShowingPasswordPrompt: Binding<Bool> {
36-
Binding(
37-
get: { authService.passwordPrompt.isPromptingPassword },
38-
set: { authService.passwordPrompt.isPromptingPassword = $0 }
39-
)
40-
}
41-
4235
public var body: some View {
36+
@Bindable var passwordPrompt = authService.passwordPrompt
4337
VStack {
4438
Text(authService.string.signedInTitle)
4539
.font(.largeTitle)
@@ -129,7 +123,7 @@ extension SignedInView: View {
129123
)
130124
.presentationDetents([.medium])
131125
}
132-
.sheet(isPresented: isShowingPasswordPrompt) {
126+
.sheet(isPresented: $passwordPrompt.isPromptingPassword) {
133127
PasswordPromptSheet(coordinator: authService.passwordPrompt)
134128
}
135129
.sheet(isPresented: $showEmailVerificationSent) {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/UpdatePasswordView.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,8 @@ public struct UpdatePasswordView {
4040
}
4141

4242
extension UpdatePasswordView: View {
43-
private var isShowingPasswordPrompt: Binding<Bool> {
44-
Binding(
45-
get: { authService.passwordPrompt.isPromptingPassword },
46-
set: { authService.passwordPrompt.isPromptingPassword = $0 }
47-
)
48-
}
49-
5043
public var body: some View {
44+
@Bindable var passwordPrompt = authService.passwordPrompt
5145
VStack(spacing: 24) {
5246
AuthTextField(
5347
text: $password,
@@ -94,7 +88,7 @@ extension UpdatePasswordView: View {
9488
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
9589
.safeAreaPadding()
9690
.navigationTitle(authService.string.passwordRecoveryTitle)
97-
.sheet(isPresented: isShowingPasswordPrompt) {
91+
.sheet(isPresented: $passwordPrompt.isPromptingPassword) {
9892
PasswordPromptSheet(coordinator: authService.passwordPrompt)
9993
}
10094
}

0 commit comments

Comments
 (0)