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:
@@ -18,6 +18,22 @@ struct LoginView: View {
|
|||||||
case username, password
|
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 {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
ZStack {
|
ZStack {
|
||||||
@@ -172,31 +188,9 @@ struct LoginView: View {
|
|||||||
|
|
||||||
// Login Button
|
// Login Button
|
||||||
Button(action: viewModel.login) {
|
Button(action: viewModel.login) {
|
||||||
HStack(spacing: AppSpacing.sm) {
|
loginButtonContent
|
||||||
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
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.disabled(viewModel.isLoading || viewModel.username.isEmpty || viewModel.password.isEmpty)
|
.disabled(!isFormValid || viewModel.isLoading)
|
||||||
|
|
||||||
// Sign Up Link
|
// Sign Up Link
|
||||||
HStack(spacing: AppSpacing.xs) {
|
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
|
// MARK: - Preview
|
||||||
|
|||||||
Reference in New Issue
Block a user