From 8e82f43aba2e5b9bb18614efdc5e27428ae79d63 Mon Sep 17 00:00:00 2001 From: Trey t Date: Mon, 10 Nov 2025 11:50:40 -0600 Subject: [PATCH] Fix SwiftUI type-checker timeout in LoginView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- iosApp/iosApp/Login/LoginView.swift | 74 +++++++++++++++++++---------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/iosApp/iosApp/Login/LoginView.swift b/iosApp/iosApp/Login/LoginView.swift index 7b417cb..a92e733 100644 --- a/iosApp/iosApp/Login/LoginView.swift +++ b/iosApp/iosApp/Login/LoginView.swift @@ -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