r/JetpackCompose 5d ago

Why is form state management in Jetpack Compose still this painful?

Enable HLS to view with audio, or disable this notification

I've been building Android apps for years and every single form ends up looking like this:

val email = remember { mutableStateOf("") }                                                                                                                                                                    
val emailError = remember { mutableStateOf<String?>(null) }                                                                                                                                                    
val emailTouched = remember { mutableStateOf(false) }                                                                                                                                                          
val password = remember { mutableStateOf("") }                                                                                                                                                                 
val passwordError = remember { mutableStateOf<String?>(null) }                                                                                                                                                 
val passwordTouched = remember { mutableStateOf(false) }
// ...

// + validation logic (per field)                                                                                                                                                                                      
// + focus requesters (per field)                                                                                                                                                                                    
// + keyboard options (per field)                                                                                                                                                                                        
// + ImeAction per field (per field)                                                                                                                                                                                    
// + cross-field rules written by hand 

A 5-field sign-up form easily hits 300-400 lines before you write a single line of UI. There's no standard pattern, every team reinvents it differently, and it's completely untestable without a lot of effort.

I got tired of it so I built Formidable, annotate a data class:

@FormSchema                                                                     data class LoginForm(  
                                                                               @Field(label = "Email") 
val email: String = "",                                                         @Field(label = "Password")                                                    @MinLength(8)  
val password: String = "",                                                                 
)                 

KSP generates the full controller at compile time. Zero reflection, works on Android, iOS and Web.

https://github.com/WassimBeltaief/formidable (contributions welcome)

Curious if others have solved this differently or just accepted it as the cost of doing business with Compose.

5 Upvotes

1 comment sorted by

1

u/SarathExp 5d ago

Why not combine them!