Skip to content

feat(sample): add full-customization example covering every auth screen - #1420

Draft
demolaf wants to merge 19 commits into
fix/clear-email-routesfrom
sample/full-customization
Draft

demolaf wants to merge 19 commits into
fix/clear-email-routesfrom
sample/full-customization

Conversation

@demolaf

@demolaf demolaf commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Related to #1400.

Adds a full customization example to the SwiftUI sample: every auth screen drawn by the app, in four live-switchable themes. Three reskin one shared layout; Professional brings its own layout through the same slots.

Changes

  • .pickerContent { state in } draws the first screen; .pickerDestination and .signedInContent replace every other screen through its content slot.
  • Doggo, Grid and Coffee Spark share one layout and differ only in theme values. Screens their designs don't cover follow the Android demo's copy.
  • Professional has its own layout: flat, left-aligned screens, providers first, a settings-style account page, and Create account pushed on the .signUp route.
  • .reauthContent draws the password, phone and email-link reauthentication prompts in each theme. The theming modifiers restyle the stock screens left: update password and delete confirmation.
  • The example owns its AuthService to enable email-link sign-in without changing other examples. Fonts ship with their OFL licenses.

Preview


Maintainer note: Fixes internal CPRN-523

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the authentication views in FirebaseAuthSwiftUI to support full UI customization by introducing customizable screen wrappers (such as EmailAuthScreen and MFAEnrolmentScreen) and extracting the stock UI into default content views. It also adds a comprehensive multi-theme customization example to the sample application. The review feedback highlights critical improvements, including reusing a static CIContext for QR code generation to prevent performance degradation, and replacing a force cast with safe optional casting to avoid potential runtime crashes.

Comment on lines +453 to +472
private func generateQRCode(from string: String) -> UIImage? {
let data = Data(string.utf8)

guard let filter = CIFilter(name: "CIQRCodeGenerator") else { return nil }
filter.setValue(data, forKey: "inputMessage")
filter.setValue("H", forKey: "inputCorrectionLevel")

guard let ciImage = filter.outputImage else { return nil }

// Scale up the QR code for better quality
let transform = CGAffineTransform(scaleX: 10, y: 10)
let scaledImage = ciImage.transformed(by: transform)

let context = CIContext()
guard let cgImage = context.createCGImage(scaledImage, from: scaledImage.extent) else {
return nil
}

return UIImage(cgImage: cgImage)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Creating a new CIContext on every invocation of generateQRCode(from:) is highly inefficient and can cause UI stuttering/performance degradation because CIContext is expensive to instantiate. It is recommended to reuse a single shared/static CIContext instance.

  private static let qrContext = CIContext()

  private func generateQRCode(from string: String) -> UIImage? {
    let data = Data(string.utf8)

    guard let filter = CIFilter(name: "CIQRCodeGenerator") else { return nil }
    filter.setValue(data, forKey: "inputMessage")
    filter.setValue("H", forKey: "inputCorrectionLevel")

    guard let ciImage = filter.outputImage else { return nil }

    // Scale up the QR code for better quality
    let transform = CGAffineTransform(scaleX: 10, y: 10)
    let scaledImage = ciImage.transformed(by: transform)

    guard let cgImage = Self.qrContext.createCGImage(scaledImage, from: scaledImage.extent) else {
      return nil
    }

    return UIImage(cgImage: cgImage)
  }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed on main, which now shares a static qrCodeContext. After the rebase this file is no longer part of this PR.

Comment on lines +124 to +133
if factor.factorID == PhoneMultiFactorID {
let phoneInfo = factor as! PhoneMultiFactorInfo
Text("SMS: \(phoneInfo.phoneNumber)")
.authFont(.caption)
.foregroundColor(.secondary)
} else {
Text("Authenticator App")
.authFont(.caption)
.foregroundColor(.secondary)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Force casting factor as! PhoneMultiFactorInfo can lead to runtime crashes if the factor is not of the expected type. It is safer and more idiomatic to use safe optional casting (as?) to prevent potential crashes.

        if let phoneInfo = factor as? PhoneMultiFactorInfo {
          Text("SMS: \(phoneInfo.phoneNumber)")
            .authFont(.caption)
            .foregroundColor(.secondary)
        } else {
          Text("Authenticator App")
            .authFont(.caption)
            .foregroundColor(.secondary)
        }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed on main, which now uses as? PhoneMultiFactorInfo here. After the rebase this file is no longer part of this PR.

Comment on lines +337 to +348
private struct DemoQRCode: View {
let image: UIImage

init?(url: URL) {
let filter = CIFilter.qrCodeGenerator()
filter.message = Data(url.absoluteString.utf8)
guard let output = filter.outputImage?.transformed(by: CGAffineTransform(scaleX: 8, y: 8)),
let cgImage = CIContext().createCGImage(output, from: output.extent) else {
return nil
}
image = UIImage(cgImage: cgImage)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instantiating a new CIContext inside the initializer of DemoQRCode is inefficient because SwiftUI views are frequently recreated. Reusing a single static CIContext avoids this overhead.

Suggested change
private struct DemoQRCode: View {
let image: UIImage
init?(url: URL) {
let filter = CIFilter.qrCodeGenerator()
filter.message = Data(url.absoluteString.utf8)
guard let output = filter.outputImage?.transformed(by: CGAffineTransform(scaleX: 8, y: 8)),
let cgImage = CIContext().createCGImage(output, from: output.extent) else {
return nil
}
image = UIImage(cgImage: cgImage)
}
private struct DemoQRCode: View {
private static let qrContext = CIContext()
let image: UIImage
init?(url: URL) {
let filter = CIFilter.qrCodeGenerator()
filter.message = Data(url.absoluteString.utf8)
guard let output = filter.outputImage?.transformed(by: CGAffineTransform(scaleX: 8, y: 8)),
let cgImage = Self.qrContext.createCGImage(output, from: output.extent) else {
return nil
}
image = UIImage(cgImage: cgImage)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4905784: DemoQRCode now shares one static CIContext.

@demolaf
demolaf force-pushed the sample/full-customization branch 2 times, most recently from 1847902 to 995a908 Compare October 22, 2026 14:20
@demolaf
demolaf force-pushed the sample/full-customization branch from edd4d3b to 293a99f Compare October 29, 2026 12:24
@demolaf
demolaf force-pushed the sample/full-customization branch from 293a99f to 1673bce Compare October 29, 2026 12:31
@demolaf
demolaf force-pushed the sample/full-customization branch from 1673bce to 1255ca6 Compare October 29, 2026 12:50
Base automatically changed from auth/phone-content-slots to main November 2, 2026 15:24
@demolaf
demolaf force-pushed the sample/full-customization branch from b915133 to 2c26a10 Compare November 18, 2026 12:37
@demolaf
demolaf marked this pull request as ready for review November 18, 2026 13:47
Adds a Full customization example to the SwiftUI sample. It replaces the first screen with .pickerContent { state in }, every pushed screen through its content slot and the signed-in screen with .signedInContent, while the library keeps auth, navigation, MFA and reauthentication.

Doggo, Grid and Coffee Spark themes come from the iOS Landing frames of the Firebase auth flows Figma file and switch live from any screen. Screens the frames don't cover follow the FirebaseUI-Android demo's copy. The theming modifiers restyle the stock screens left in the flow.
Starts sign-in from the other-providers sheet after it dismisses, creates the example's AuthService when it appears rather than when ContentView builds the link, anchors the mascot to the form's trailing edge, generates the TOTP QR code once per URL, disables Remove while an unenrolment runs, gives sheet providers an icon, and ships the spark background at 2x only.
The form and footer now keep the Figma frame's 332 and 334 point widths, centred, instead of fixed 49 and 48 point insets that only fit the 430 point frame and squeezed the form on narrower phones.
The background sat in the scroll view's .background, so it shrank with the scroll view and left white edges once the form had a maximum width. It is now a ZStack layer behind a full-width scroll view.
The remaining providers open from a pill styled like Google's instead of a text link, so the three buttons keep Figma's 12 point spacing. The flow switch gets a 44 point tap target, and text links get a taller tap area without changing the layout.
…sheet

Providers the Figma frames don't draw now appear as the library's AuthProviderButton with each provider's own label and ProviderStyle, instead of improvised pills. The action still goes through AuthMethodPickerState.select once the sheet has closed.
The switch toggles the email form, so it now sits right below the form and above the other sign-in methods divider, rather than under the provider buttons where the Figma frames place it.
The switch text now sits 24 points from the form above and the divider below in every theme. The per-theme form-to-divider spacing it replaced is removed.
The enrolment steps move into DemoMFAEnrolmentContent so a preview can render the TOTP setup step from a stub MFAEnrollmentContentState. The Auth emulator only enrols SMS factors, so the step can't be reached against it.
Every demo screen now uses one content width: 32 points from the sheet's edges, capped at 480 points. The Figma frames' 332 point form left 49 points each side on a 430 point phone, which was too much.
A spec-defined theme with no Figma frame: the system font, neutral greys with one blue accent, 10 point corners, hairline borders, no background art, and light and dark variants. It reuses the shared layout; the theme adds button height, card border and pill fill, border and corner tokens, which the Figma themes set to their existing values.
Professional now brings its own screens through the same slots instead of reskinning the shared layout: flat, left-aligned pages with labelled fields, sign-in providers first, a separate Create account screen pushed on the .signUp route, a settings-style account page and grouped two-factor choices. The Figma themes keep the shared layout and their in-place sign-in / sign-up switch. The Professional dark accent fill is darkened so white labels keep 4.5:1 contrast.
Reset password and the two-factor method choice had a text link that only went back a screen, which the navigation bar's back button already does.
- Ask for the email when a sign-in link is opened on another device.
- Respect isEmailSignInEnabled, canSignUp and requiresDisplayName, and turn on the name field.
- Go back to the sign-in form from a pushed sign-up screen, and draw .signUp in the shared layout.
- Keep a default case for ReauthPrompt and the MFA enrolment step.
- Offer a password change only to accounts that sign in with a password.
- Keep Doggo, Grid and Coffee Spark light, scale Professional text with Dynamic Type, and outline the stock fields.
@demolaf
demolaf force-pushed the sample/full-customization branch from 262cc9c to 773a36d Compare November 18, 2026 15:44
@demolaf
demolaf changed the base branch from main to fix/clear-email-routes November 18, 2026 15:44
@demolaf
demolaf added this pull request to stack #1439 November 18, 2026 15:44
@demolaf
demolaf marked this pull request as draft November 18, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant