Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use navigation scoped ViewModel for SettingViewModel #608

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ 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
fun ProvideViewModels(content: @Composable () -> Unit) {
CompositionLocalProvider(
provideAppViewModelFactory { hiltViewModel<RealAppViewModel>() },
provideFeedViewModelFactory { hiltViewModel<RealFeedViewModel>() },
settingViewModelProviderValue(viewModel<RealSettingViewModel>()),
provideSettingViewModelFactory { hiltViewModel<RealSettingViewModel>() },
staffViewModelProviderValue(viewModel<RealStaffViewModel>()),
contributorViewModelProviderValue(fakeContributorViewModel()),
fmPlayerViewModelProviderValue(viewModel<RealFmPlayerViewModel>()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ interface SettingViewModel :
override fun event(event: Event)
}

private val LocalSettingViewModel = compositionLocalOf<SettingViewModel> {
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()