mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Use CompositionLocal
This commit is contained in:
parent
fa83626852
commit
ab180b66dc
3 changed files with 13 additions and 4 deletions
|
@ -8,8 +8,6 @@ import androidx.compose.ui.res.stringResource
|
|||
import dev.yokai.presentation.component.preference.Preference
|
||||
|
||||
interface ComposableSettings {
|
||||
fun getOnBackPress(): () -> Unit = {}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
@StringRes
|
||||
|
@ -26,7 +24,6 @@ interface ComposableSettings {
|
|||
SettingsScaffold(
|
||||
title = stringResource(getTitleRes()),
|
||||
itemsProvider = { getPreferences() },
|
||||
onBackPress = getOnBackPress(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package dev.yokai.presentation.settings
|
|||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.items
|
||||
|
@ -21,23 +22,26 @@ import dev.yokai.presentation.component.preference.PreferenceItem
|
|||
import dev.yokai.presentation.component.preference.widget.PreferenceGroupHeader
|
||||
import eu.kanade.tachiyomi.core.preference.collectAsState
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.compose.LocalBackPress
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
@Composable
|
||||
fun SettingsScaffold(
|
||||
title: String,
|
||||
appBarType: AppBarType? = null,
|
||||
onBackPress: (() -> Unit)? = null,
|
||||
appBarActions: @Composable RowScope.() -> Unit = {},
|
||||
itemsProvider: @Composable () -> List<Preference>,
|
||||
) {
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
val useLargeAppBar by preferences.useLargeToolbar().collectAsState()
|
||||
val listState = rememberLazyListState()
|
||||
val onBackPress = LocalBackPress.current
|
||||
|
||||
YokaiScaffold(
|
||||
onNavigationIconClicked = onBackPress ?: {},
|
||||
title = title,
|
||||
appBarType = appBarType ?: if (useLargeAppBar) AppBarType.LARGE else AppBarType.SMALL,
|
||||
actions = appBarActions,
|
||||
scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(
|
||||
state = rememberTopAppBarState(),
|
||||
canScroll = { listState.firstVisibleItemIndex > 0 || listState.firstVisibleItemScrollOffset > 0 },
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package eu.kanade.tachiyomi.util.compose
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ProvidableCompositionLocal
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
|
||||
val LocalBackPress: ProvidableCompositionLocal<(() -> Unit)?> = staticCompositionLocalOf { null }
|
||||
val LocalAlertDialog: ProvidableCompositionLocal<(@Composable () -> Unit)?> = staticCompositionLocalOf { null }
|
Loading…
Add table
Add a link
Reference in a new issue