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 360573193..9625cdec1 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 @@ -452,7 +452,7 @@ fun FilterItemCountRow(count: String) { fun PreviewFeedScreen() { AppThemeWithBackground { CompositionLocalProvider( - feedViewModelProviderValue(fakeFeedViewModel()), + provideFeedViewModelFactory { fakeFeedViewModel() }, fmPlayerViewModelProviderValue(fakeFmPlayerViewModel()) ) { FeedScreen( @@ -473,7 +473,7 @@ fun PreviewDarkFeedScreen() { theme = Theme.DARK ) { CompositionLocalProvider( - feedViewModelProviderValue(fakeFeedViewModel()), + provideFeedViewModelFactory { fakeFeedViewModel() }, fmPlayerViewModelProviderValue(fakeFmPlayerViewModel()) ) { FeedScreen( @@ -492,7 +492,7 @@ fun PreviewDarkFeedScreen() { fun PreviewFeedScreenWithStartBlog() { AppThemeWithBackground { CompositionLocalProvider( - feedViewModelProviderValue(fakeFeedViewModel()), + provideFeedViewModelFactory { fakeFeedViewModel() }, fmPlayerViewModelProviderValue(fakeFmPlayerViewModel()) ) { FeedScreen( diff --git a/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FeedViewModel.kt b/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FeedViewModel.kt index 35e294cfa..4738fa147 100644 --- a/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FeedViewModel.kt +++ b/uicomponent-compose/feed/src/main/java/io/github/droidkaigi/feeder/feed/FeedViewModel.kt @@ -33,12 +33,14 @@ interface FeedViewModel : override fun event(event: Event) } -private val LocalFeedViewModel = compositionLocalOf { - error("not LocalFeedViewModel provided") +private val LocalFeedViewModel = compositionLocalOf<@Composable () -> FeedViewModel> { + { + error("not LocalFeedViewModel provided") + } } -fun feedViewModelProviderValue(viewModel: FeedViewModel) = +fun provideFeedViewModelFactory(viewModel: @Composable () -> FeedViewModel) = LocalFeedViewModel provides viewModel @Composable -fun feedViewModel() = LocalFeedViewModel.current +fun feedViewModel() = LocalFeedViewModel.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 6c84963c8..7d7b1138a 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 @@ -6,8 +6,8 @@ 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.feedViewModelProviderValue 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.staff.staffViewModelProviderValue @@ -18,7 +18,7 @@ fun ProvideViewModels(content: @Composable () -> Unit) { provideAppViewModelFactory { hiltViewModel() }, - feedViewModelProviderValue(viewModel()), + provideFeedViewModelFactory { hiltViewModel() }, settingViewModelProviderValue(viewModel()), staffViewModelProviderValue(viewModel()), contributorViewModelProviderValue(fakeContributorViewModel()),