diff --git a/uicomponent-compose/main/src/main/java/io/github/droidkaigi/feeder/viewmodel/ProvideRealViewModels.kt b/uicomponent-compose/main/src/main/java/io/github/droidkaigi/feeder/viewmodel/ProvideRealViewModels.kt index cb075a193..246d5ca8b 100644 --- a/uicomponent-compose/main/src/main/java/io/github/droidkaigi/feeder/viewmodel/ProvideRealViewModels.kt +++ b/uicomponent-compose/main/src/main/java/io/github/droidkaigi/feeder/viewmodel/ProvideRealViewModels.kt @@ -9,7 +9,7 @@ import io.github.droidkaigi.feeder.contributor.fakeContributorViewModel import io.github.droidkaigi.feeder.feed.fmPlayerViewModelProviderValue import io.github.droidkaigi.feeder.feed.provideFeedViewModelFactory import io.github.droidkaigi.feeder.provideAppViewModelFactory -import io.github.droidkaigi.feeder.setting.settingViewModelProviderValue +import io.github.droidkaigi.feeder.setting.provideSettingViewModelFactory import io.github.droidkaigi.feeder.staff.staffViewModelProviderValue @Composable @@ -17,7 +17,7 @@ fun ProvideViewModels(content: @Composable () -> Unit) { CompositionLocalProvider( provideAppViewModelFactory { hiltViewModel() }, provideFeedViewModelFactory { hiltViewModel() }, - settingViewModelProviderValue(viewModel()), + provideSettingViewModelFactory { hiltViewModel() }, staffViewModelProviderValue(viewModel()), contributorViewModelProviderValue(fakeContributorViewModel()), fmPlayerViewModelProviderValue(viewModel()), diff --git a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/setting/SettingViewModel.kt b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/setting/SettingViewModel.kt index 82a43bf72..4f81e2f55 100644 --- a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/setting/SettingViewModel.kt +++ b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/setting/SettingViewModel.kt @@ -30,12 +30,15 @@ interface SettingViewModel : override fun event(event: Event) } -private val LocalSettingViewModel = compositionLocalOf { - error("not LocalSettingViewModel provided") -} +private val LocalSettingViewModelFactory = + compositionLocalOf<@Composable () -> SettingViewModel> { + { + error("not LocalSettingViewModelFactory provided") + } + } -fun settingViewModelProviderValue(viewModel: SettingViewModel) = - LocalSettingViewModel provides viewModel +fun provideSettingViewModelFactory(viewModelFactory: @Composable () -> SettingViewModel) = + LocalSettingViewModelFactory provides viewModelFactory @Composable -fun settingViewModel() = LocalSettingViewModel.current +fun settingViewModel() = LocalSettingViewModelFactory.current()