Create lifecycle-aware VM by viewModelWithLifecycle#230
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a reusable Compose helper to create ViewModels that automatically register/unregister themselves as lifecycle observers, then refactors multiple screens to use that helper instead of duplicating DisposableEffect blocks.
Changes:
- Added
viewModelWithLifecycle()composable helper that wrapsviewModel()and conditionally attaches the VM toLocalLifecycleOwnerwhen it implementsLifecycleObserver. - Replaced per-screen
DisposableEffect(lifecycleOwner, viewModel)lifecycle wiring withviewModelWithLifecycle()defaults across settings/home/profile/proxy/log UIs. - Removed now-unused imports (
DisposableEffect,LocalLifecycleOwner,viewModel) from updated screens.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ui/src/main/kotlin/com/github/kr328/clash/ui/lifecycle/ViewModel.kt | Adds viewModelWithLifecycle() helper to centralize lifecycle observer registration for VMs. |
| ui/settings/src/main/kotlin/com/github/kr328/clash/settings/ui/OverrideSettingsScreen.kt | Switches VM acquisition to viewModelWithLifecycle() and removes manual lifecycle observer wiring. |
| ui/settings/src/main/kotlin/com/github/kr328/clash/settings/ui/MetaFeatureSettingsScreen.kt | Same refactor: use viewModelWithLifecycle() and drop duplicated DisposableEffect. |
| ui/settings/src/main/kotlin/com/github/kr328/clash/settings/ui/AccessControlScreen.kt | Same refactor to the new lifecycle-aware VM helper. |
| ui/proxy/src/main/kotlin/com/github/kr328/clash/proxy/ui/ProxyScreen.kt | Same refactor to remove manual lifecycle observer wiring. |
| ui/profile/src/main/kotlin/com/github/kr328/clash/profile/ui/ProvidersScreen.kt | Same refactor to use viewModelWithLifecycle(). |
| ui/profile/src/main/kotlin/com/github/kr328/clash/profile/ui/PropertiesScreen.kt | Same refactor to use viewModelWithLifecycle(). |
| ui/profile/src/main/kotlin/com/github/kr328/clash/profile/ui/ProfilesScreen.kt | Same refactor to use viewModelWithLifecycle(). |
| ui/profile/src/main/kotlin/com/github/kr328/clash/profile/ui/FilesScreen.kt | Same refactor to use viewModelWithLifecycle(). |
| ui/log/src/main/kotlin/com/github/kr328/clash/log/ui/LogcatScreen.kt | Same refactor to use viewModelWithLifecycle(). |
| ui/home/src/main/kotlin/com/github/kr328/clash/home/ui/HomeScreen.kt | Same refactor to use viewModelWithLifecycle(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8ace576 to
228fedc
Compare
228fedc to
5e99247
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.