diff --git a/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FeedScreen.kt b/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FeedScreen.kt index 0da89888a..b5e7eb903 100644 --- a/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FeedScreen.kt +++ b/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FeedScreen.kt @@ -458,7 +458,7 @@ fun PreviewFeedScreen() { AppThemeWithBackground { CompositionLocalProvider( provideFeedViewModelFactory { fakeFeedViewModel() }, - fmPlayerViewModelProviderValue(fakeFmPlayerViewModel()) + provideFmPlayerViewModelFactory { fakeFmPlayerViewModel() } ) { FeedScreen( selectedTab = FeedTab.Home, @@ -479,7 +479,7 @@ fun PreviewDarkFeedScreen() { ) { CompositionLocalProvider( provideFeedViewModelFactory { fakeFeedViewModel() }, - fmPlayerViewModelProviderValue(fakeFmPlayerViewModel()) + provideFmPlayerViewModelFactory { fakeFmPlayerViewModel() } ) { FeedScreen( selectedTab = FeedTab.Home, @@ -498,7 +498,7 @@ fun PreviewFeedScreenWithStartBlog() { AppThemeWithBackground { CompositionLocalProvider( provideFeedViewModelFactory { fakeFeedViewModel() }, - fmPlayerViewModelProviderValue(fakeFmPlayerViewModel()) + provideFmPlayerViewModelFactory { fakeFmPlayerViewModel() } ) { FeedScreen( selectedTab = FeedTab.FilteredFeed.Blog, diff --git a/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FmPlayerViewModel.kt b/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FmPlayerViewModel.kt index 73fd734e5..1d8e86320 100644 --- a/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FmPlayerViewModel.kt +++ b/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FmPlayerViewModel.kt @@ -30,12 +30,15 @@ interface FmPlayerViewModel : UnidirectionalViewModel { - error("not LocalFmPlayerViewModel provided") -} +private val LocalFmPlayerViewModelFactory = + compositionLocalOf<@Composable () -> FmPlayerViewModel> { + { + error("not LocalFmPlayerViewModel provided") + } + } -fun fmPlayerViewModelProviderValue(viewModel: FmPlayerViewModel) = - LocalFmPlayerViewModel provides viewModel +fun provideFmPlayerViewModelFactory(viewModelFactory: @Composable () -> FmPlayerViewModel) = + LocalFmPlayerViewModelFactory provides viewModelFactory @Composable -fun fmPlayerViewModel() = LocalFmPlayerViewModel.current +fun fmPlayerViewModel() = LocalFmPlayerViewModelFactory.current() 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 246d5ca8b..c791d48ac 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 @@ -3,14 +3,13 @@ package io.github.droidkaigi.feeder.viewmodel import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.hilt.navigation.compose.hiltViewModel -import androidx.lifecycle.viewmodel.compose.viewModel -import io.github.droidkaigi.feeder.contributor.contributorViewModelProviderValue import io.github.droidkaigi.feeder.contributor.fakeContributorViewModel -import io.github.droidkaigi.feeder.feed.fmPlayerViewModelProviderValue +import io.github.droidkaigi.feeder.contributor.provideContributorViewModelFactory import io.github.droidkaigi.feeder.feed.provideFeedViewModelFactory +import io.github.droidkaigi.feeder.feed.provideFmPlayerViewModelFactory import io.github.droidkaigi.feeder.provideAppViewModelFactory import io.github.droidkaigi.feeder.setting.provideSettingViewModelFactory -import io.github.droidkaigi.feeder.staff.staffViewModelProviderValue +import io.github.droidkaigi.feeder.staff.provideStaffViewModelFactory @Composable fun ProvideViewModels(content: @Composable () -> Unit) { @@ -18,9 +17,9 @@ fun ProvideViewModels(content: @Composable () -> Unit) { provideAppViewModelFactory { hiltViewModel() }, provideFeedViewModelFactory { hiltViewModel() }, provideSettingViewModelFactory { hiltViewModel() }, - staffViewModelProviderValue(viewModel()), - contributorViewModelProviderValue(fakeContributorViewModel()), - fmPlayerViewModelProviderValue(viewModel()), + provideStaffViewModelFactory { (hiltViewModel()) }, + provideContributorViewModelFactory { fakeContributorViewModel() }, + provideFmPlayerViewModelFactory { hiltViewModel() }, content = content ) } diff --git a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorItem.kt b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorItem.kt index f551ab9db..89ef3532d 100644 --- a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorItem.kt +++ b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorItem.kt @@ -66,7 +66,11 @@ fun ContributorItem(contributor: Contributor, onClickItem: (Contributor) -> Unit fun PreviewContributorItem() { ConferenceAppFeederTheme { val contributor = fakeContributors().first() - CompositionLocalProvider(contributorViewModelProviderValue(fakeContributorViewModel())) { + CompositionLocalProvider( + provideContributorViewModelFactory { + fakeContributorViewModel() + } + ) { ContributorItem(contributor = contributor) { } } diff --git a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorList.kt b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorList.kt index 607b01c19..3c8d3ff66 100644 --- a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorList.kt +++ b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorList.kt @@ -46,7 +46,11 @@ fun ContributorList(onContributorClick: (Contributor) -> Unit) { @Composable fun PreviewContributorScreen() { ConferenceAppFeederTheme { - CompositionLocalProvider(contributorViewModelProviderValue(fakeContributorViewModel())) { + CompositionLocalProvider( + provideContributorViewModelFactory { + fakeContributorViewModel() + } + ) { ContributorList() { } } diff --git a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorViewModel.kt b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorViewModel.kt index f0c1dadd3..e3cefe060 100644 --- a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorViewModel.kt +++ b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/contributor/ContributorViewModel.kt @@ -30,12 +30,15 @@ interface ContributorViewModel : override fun event(event: Event) } -private val LocalContributeViewModel = compositionLocalOf { - error("Not view model provided") -} +private val LocalContributeViewModelFactory = + compositionLocalOf<@Composable () -> ContributorViewModel> { + { + error("Not view model provided") + } + } -fun contributorViewModelProviderValue(viewModel: ContributorViewModel) = - LocalContributeViewModel provides viewModel +fun provideContributorViewModelFactory(viewModelFactory: @Composable () -> ContributorViewModel) = + LocalContributeViewModelFactory provides viewModelFactory @Composable -fun contributeViewModel() = LocalContributeViewModel.current +fun contributeViewModel() = LocalContributeViewModelFactory.current() diff --git a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffItem.kt b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffItem.kt index f93f8a1ed..c763513c2 100644 --- a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffItem.kt +++ b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffItem.kt @@ -80,7 +80,7 @@ fun StaffItem(staff: Staff, onClickItem: (Staff) -> Unit) { fun PreviewStaffItem() { ConferenceAppFeederTheme { val staff = fakeStaffs().first() - CompositionLocalProvider(staffViewModelProviderValue(fakeStaffViewModel())) { + CompositionLocalProvider(provideStaffViewModelFactory { fakeStaffViewModel() }) { StaffItem(staff = staff) { } } diff --git a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffList.kt b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffList.kt index 3410af269..4a983602a 100644 --- a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffList.kt +++ b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffList.kt @@ -46,7 +46,7 @@ fun StaffList(onStaffClick: (Staff) -> Unit) { @Composable fun PreviewStaffScreen() { ConferenceAppFeederTheme { - CompositionLocalProvider(staffViewModelProviderValue(fakeStaffViewModel())) { + CompositionLocalProvider(provideStaffViewModelFactory { fakeStaffViewModel() }) { StaffList {} } } diff --git a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffViewModel.kt b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffViewModel.kt index 4616010fd..ee6b4814e 100644 --- a/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffViewModel.kt +++ b/uicomponent-compose/other/src/main/java/io/github/droidkaigi/feeder/staff/StaffViewModel.kt @@ -26,11 +26,14 @@ interface StaffViewModel : override fun event(event: Event) } -private val LocalStaffViewModel = compositionLocalOf { - error("Not view model provided") +private val LocalStaffViewModelFactory = compositionLocalOf<@Composable () -> StaffViewModel> { + { + error("Not view model provided") + } } -fun staffViewModelProviderValue(viewModel: StaffViewModel) = LocalStaffViewModel provides viewModel +fun provideStaffViewModelFactory(viewModelFactory: @Composable () -> StaffViewModel) = + LocalStaffViewModelFactory provides viewModelFactory @Composable -fun staffViewModel() = LocalStaffViewModel.current +fun staffViewModel() = LocalStaffViewModelFactory.current()