Fix SwiftUI type-checker timeout in LoginView

Broke up complex expressions into computed properties and subviews to help the Swift compiler type-check the view hierarchy.

Changes:
- Extracted isFormValid computed property
- Extracted loginButtonContent as separate view
- Extracted loginButtonBackground with @ViewBuilder
- Simplified button disabled condition

This resolves "The compiler is unable to type-check this expression in reasonable time" error.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-11-10 11:50:40 -06:00
parent b7e0b6fefc
commit 8e82f43aba

View File

@@ -18,6 +18,22 @@ struct LoginView: View {
case username, password
}
// Computed properties to help type checker
private var isFormValid: Bool {
!viewModel.username.isEmpty && !viewModel.password.isEmpty
}
private var buttonBackgroundColor: Color {
if viewModel.isLoading || !isFormValid {
return AppColors.textTertiary
}
return .clear
}
private var shouldShowShadow: Bool {
isFormValid && !viewModel.isLoading
}
var body: some View {
NavigationView {
ZStack {
@@ -172,31 +188,9 @@ struct LoginView: View {
// Login Button
Button(action: viewModel.login) {
HStack(spacing: AppSpacing.sm) {
if viewModel.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
}
Text(viewModel.isLoading ? "Signing In..." : "Sign In")
.font(AppTypography.titleSmall)
.fontWeight(.semibold)
}
.frame(maxWidth: .infinity)
.frame(height: 56)
.foregroundColor(.white)
.background(
viewModel.isLoading || viewModel.username.isEmpty || viewModel.password.isEmpty
? AppColors.textTertiary
: AppColors.primaryGradient
)
.cornerRadius(AppRadius.md)
.shadow(
color: viewModel.username.isEmpty || viewModel.password.isEmpty ? .clear : AppColors.primary.opacity(0.3),
radius: 10,
y: 5
)
loginButtonContent
}
.disabled(viewModel.isLoading || viewModel.username.isEmpty || viewModel.password.isEmpty)
.disabled(!isFormValid || viewModel.isLoading)
// Sign Up Link
HStack(spacing: AppSpacing.xs) {
@@ -273,6 +267,38 @@ struct LoginView: View {
}
}
}
// MARK: - Subviews
private var loginButtonContent: some View {
HStack(spacing: AppSpacing.sm) {
if viewModel.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
}
Text(viewModel.isLoading ? "Signing In..." : "Sign In")
.font(AppTypography.titleSmall)
.fontWeight(.semibold)
}
.frame(maxWidth: .infinity)
.frame(height: 56)
.foregroundColor(.white)
.background(loginButtonBackground)
.cornerRadius(AppRadius.md)
.shadow(
color: shouldShowShadow ? AppColors.primary.opacity(0.3) : .clear,
radius: 10,
y: 5
)
}
@ViewBuilder
private var loginButtonBackground: some View {
if viewModel.isLoading || !isFormValid {
AppColors.textTertiary
} else {
AppColors.primaryGradient
}
}
}
// MARK: - Preview