Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auth] Convert LoginView to SwiftUI #13628

Merged
merged 22 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improvements:
ncooke3 committed Dec 11, 2024
commit 8c337f37bfc53448c3473e4a210ea3a45d870df9
Original file line number Diff line number Diff line change
@@ -71,5 +71,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private func configureApplicationAppearance() {
UINavigationBar.appearance().tintColor = .systemOrange
UITabBar.appearance().tintColor = .systemOrange
// Handles iOS 15 behavior change where tab bar become translucent during transitions.
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
UITabBar.appearance().scrollEdgeAppearance = appearance
}
}
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -29,51 +29,42 @@ struct LoginView: View {
}

var body: some View {
Group {
VStack {
Group {
HStack {
VStack {
Text("Email/Password Auth")
.font(.title)
.bold()
}
Spacer()
}
HStack {
Text(
"Login or create an account using the Email/Password auth " +
"provider.\n\nEnsure that the Email/Password provider is " +
"enabled on the Firebase console for the given project."
)
.fixedSize(horizontal: false, vertical: true)
Spacer()
}
}
.padding(.vertical)

Spacer()
TextField("Email", text: $email)
.textFieldStyle(SymbolTextField(symbolName: "person.crop.circle"))
TextField("Password", text: $password)
.textFieldStyle(SymbolTextField(symbolName: "lock.fill"))
Spacer()
Group {
LoginViewButton(
text: "Login",
accentColor: .white,
backgroundColor: .orange,
action: login
)
LoginViewButton(
text: "Create Account",
accentColor: .orange,
backgroundColor: .primary,
action: createUser
VStack {
Group {
HStack {
Text(
"Login or create an account using the Email/Password auth " +
"provider.\n\nEnsure that the Email/Password provider is " +
"enabled on the Firebase console for the given project."
)
.fixedSize(horizontal: false, vertical: true)
Spacer()
}
.disabled(email.isEmpty || password.isEmpty)
}
.padding(.bottom)

TextField("Email", text: $email)
.textFieldStyle(SymbolTextField(symbolName: "person.crop.circle"))
TextField("Password", text: $password)
.textFieldStyle(SymbolTextField(symbolName: "lock.fill"))
.padding(.bottom)

Group {
LoginViewButton(
text: "Login",
accentColor: .white,
backgroundColor: .orange,
action: login
)
LoginViewButton(
text: "Create Account",
accentColor: .orange,
backgroundColor: .primary,
action: createUser
)
}
.disabled(email.isEmpty || password.isEmpty)

Spacer()
}
.padding()
@@ -85,6 +76,10 @@ struct LoginView: View {
_ = try await AppManager.shared
.auth()
.signIn(withEmail: email, password: password)
await MainActor.run {
dismiss()
delegate?.loginDidOccur(resolver: nil)
}
// TODO(ncooke3): Investigate possible improvements.
// } catch let error as AuthErrorCode
// where error.code == .secondFactorRequired {
Original file line number Diff line number Diff line change
@@ -340,6 +340,7 @@ class AuthViewController: UIViewController, DataSourceProviderDelegate {
private func performDemoEmailPasswordLoginFlow() {
let loginView = LoginView(delegate: self)
let hostingController = UIHostingController(rootView: loginView)
hostingController.title = "Email/Password Auth"
navigationController?.pushViewController(hostingController, animated: true)
}


Unchanged files with check annotations Beta

// MARK: Extending UITabBarController to work with custom transition animator
extension UITabBarController: UITabBarControllerDelegate {

Check warning on line 200 in FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift

GitHub Actions / integration-tests (ObjCApiTests)

extension declares a conformance of imported type 'UITabBarController' to imported protocol 'UITabBarControllerDelegate'; this will not behave correctly if the owners of 'UIKit' introduce this conformance in the future

Check warning on line 200 in FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift

GitHub Actions / integration-tests (ObjCApiTests)

extension declares a conformance of imported type 'UITabBarController' to imported protocol 'UITabBarControllerDelegate'; this will not behave correctly if the owners of 'UIKit' introduce this conformance in the future

Check warning on line 200 in FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift

GitHub Actions / integration-tests (SwiftApiTests)

extension declares a conformance of imported type 'UITabBarController' to imported protocol 'UITabBarControllerDelegate'; this will not behave correctly if the owners of 'UIKit' introduce this conformance in the future

Check warning on line 200 in FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift

GitHub Actions / integration-tests (SwiftApiTests)

extension declares a conformance of imported type 'UITabBarController' to imported protocol 'UITabBarControllerDelegate'; this will not behave correctly if the owners of 'UIKit' introduce this conformance in the future

Check warning on line 200 in FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

extension declares a conformance of imported type 'UITabBarController' to imported protocol 'UITabBarControllerDelegate'; this will not behave correctly if the owners of 'UIKit' introduce this conformance in the future

Check warning on line 200 in FirebaseAuth/Tests/SampleSwift/AuthenticationExample/Utility/Extensions.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

extension declares a conformance of imported type 'UITabBarController' to imported protocol 'UITabBarControllerDelegate'; this will not behave correctly if the owners of 'UIKit' introduce this conformance in the future
public func tabBarController(_ tabBarController: UITabBarController,
animationControllerForTransitionFrom fromVC: UIViewController,
to toVC: UIViewController)
"Signed user does not match request.")
// Regression test for #13550. Auth enumeration protection is enabled for
// the test project, so no sign in methods should be returned.
let signInMethods = try await auth.fetchSignInMethods(forEmail: kExistingEmailToSignIn)

Check warning on line 80 in FirebaseAuth/Tests/SampleSwift/SwiftApiTests/EmailPasswordTests.swift

GitHub Actions / integration-tests (SwiftApiTests)

'fetchSignInMethods(forEmail:)' is deprecated: `fetchSignInMethods` is deprecated and will be removed in a future release. This method returns an empty list when Email Enumeration Protection is enabled.
XCTAssertEqual(signInMethods, [])
}
}
func wait(forElement element: XCUIElement, timeout: TimeInterval) {
let predicate = NSPredicate(format: "exists == 1")
expectation(for: predicate, evaluatedWith: element)
waitForExpectations(timeout: timeout)

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testAuthExistingAccountWrongPassword, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testCreateAccountBadPassword, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testCreateAlreadyExistingAccount, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testAuthExistingAccountWrongPassword, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testCreateAccountBadPassword, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testCreateAlreadyExistingAccount, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testAuthExistingAccountWrongPassword, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testCreateAccountBadPassword, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".

Check failure on line 249 in FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/AuthenticationExampleUITests.swift

GitHub Actions / integration-tests (AuthenticationExampleUITests)

testCreateAlreadyExistingAccount, Asynchronous wait failed: Exceeded timeout of 5 seconds, with unfulfilled expectations: "Expect predicate `exists == 1` for object "Error" StaticText".
}
}