Skip to content

Create lifecycle-aware VM by viewModelWithLifecycle#230

Merged
Goooler merged 1 commit into
trunkfrom
view-model-with-lifecycle
May 12, 2026
Merged

Create lifecycle-aware VM by viewModelWithLifecycle#230
Goooler merged 1 commit into
trunkfrom
view-model-with-lifecycle

Conversation

@Goooler
Copy link
Copy Markdown
Owner

@Goooler Goooler commented May 12, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 wraps viewModel() and conditionally attaches the VM to LocalLifecycleOwner when it implements LifecycleObserver.
  • Replaced per-screen DisposableEffect(lifecycleOwner, viewModel) lifecycle wiring with viewModelWithLifecycle() 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.

@Goooler Goooler force-pushed the view-model-with-lifecycle branch 2 times, most recently from 8ace576 to 228fedc Compare May 12, 2026 15:56
@Goooler Goooler force-pushed the view-model-with-lifecycle branch from 228fedc to 5e99247 Compare May 12, 2026 15:58
@Goooler Goooler merged commit 2b5f8a9 into trunk May 12, 2026
3 checks passed
@Goooler Goooler deleted the view-model-with-lifecycle branch May 12, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants