google / google/ground-android
[Code health] Refactor composables to correct patterns
- Dominant language
- Kotlin
- Stars
- 293
- Forks
- 149
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 42
Description
There are some issues with the current Compose setup that should be addressed:
**State management**
- Composables should follow a declarative pattern rather than an imperative oneto enable automatic UI updates through recomposition
- `TaskButton` is written like a xml compound view. `AbstractTaskFragment` has to add/remove the components manually instead of relying on recomposition #3437
- `HomeScreenFragment.showSignOutConfirmationDialogs` creates new mutable states and composables on every click, bypassing recomposition entirely #3438
- Composables should not manage their own internal state, it should ideally be hoisted to allow for stability and reusability.
- `DataSharingTermsDialog`; `InstructionsDialog` ; `ConfirmationDialog` ; `LoiJobSheet` - manage their own visibility #3439
**Data flow**
- There should be an unidirectional data flow. The ViewModels should own the state and be the single source of truth for composables. This is not always the case:
- `SurveyList` receives the survey list and then sends it back to the VM. This sets an unnecessary circular flow of data #3440
- State should be collected using `collectAsStateWithLifecycle` instead of just `collectAsState` in order to save resources and avoid memory leaks (eg. `HomeScreenFragment`; `SurveyList`)
**Lifecycle and resources**
- Font families should be centralized and defined in a typography file which is then used by the AppTheme #3441
Contributor guide
Assessment
This issue has not been assessed yet.