Skip to content

Commit

Permalink
Deduplicate and improve Scrollbar theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Nov 11, 2024
1 parent aea2b7c commit fdf36cb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.schabi.newpipe.ui.components.common

import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import my.nanihadesuka.compose.ScrollbarSettings

@Composable
fun defaultThemedScrollbarSettings(): ScrollbarSettings = ScrollbarSettings.Default.copy(
thumbUnselectedColor = MaterialTheme.colorScheme.primary,
thumbSelectedColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.75f),
)

@Composable
fun LazyColumnThemedScrollbar(
state: LazyListState,
modifier: Modifier = Modifier,
settings: ScrollbarSettings = defaultThemedScrollbarSettings(),
indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null,
content: @Composable () -> Unit
) {
my.nanihadesuka.compose.LazyColumnScrollbar(
state = state,
modifier = modifier,
settings = settings,
indicatorContent = indicatorContent,
content = content,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,21 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.stringResource
import androidx.preference.PreferenceManager
import androidx.window.core.layout.WindowWidthSizeClass
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.ScrollbarSettings
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.InfoItem
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.info_list.ItemViewMode
import org.schabi.newpipe.ktx.findFragmentActivity
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
import org.schabi.newpipe.ui.components.items.playlist.PlaylistListItem
import org.schabi.newpipe.ui.components.items.stream.StreamListItem
import org.schabi.newpipe.ui.theme.md_theme_dark_primary
import org.schabi.newpipe.util.DependentPreferenceHelper
import org.schabi.newpipe.util.NavigationHelper

Expand Down Expand Up @@ -75,13 +72,7 @@ fun ItemList(
} else {
val state = rememberLazyListState()

LazyColumnScrollbar(
state = state,
settings = ScrollbarSettings.Default.copy(
thumbSelectedColor = md_theme_dark_primary,
thumbUnselectedColor = Color.Red
)
) {
LazyColumnThemedScrollbar(state = state) {
LazyColumn(modifier = nestedScrollModifier, state = state) {
listHeader()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.pluralStringResource
Expand All @@ -33,16 +32,14 @@ import androidx.paging.compose.collectAsLazyPagingItems
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.ScrollbarSettings
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.comments.CommentsInfoItem
import org.schabi.newpipe.extractor.stream.Description
import org.schabi.newpipe.paging.CommentRepliesSource
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
import org.schabi.newpipe.ui.components.common.LoadingIndicator
import org.schabi.newpipe.ui.components.common.NoItemsMessage
import org.schabi.newpipe.ui.theme.AppTheme
import org.schabi.newpipe.ui.theme.md_theme_dark_primary

@Composable
fun CommentRepliesDialog(
Expand Down Expand Up @@ -94,13 +91,7 @@ private fun CommentRepliesDialog(
// content color for MaterialTheme.colorScheme.background instead
LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background)
) {
LazyColumnScrollbar(
state = listState,
settings = ScrollbarSettings.Default.copy(
thumbSelectedColor = md_theme_dark_primary,
thumbUnselectedColor = Color.Red
)
) {
LazyColumnThemedScrollbar(state = listState) {
LazyColumn(
modifier = Modifier.nestedScroll(nestedScrollInterop),
state = listState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.pluralStringResource
Expand All @@ -23,16 +22,14 @@ import androidx.paging.PagingData
import androidx.paging.compose.collectAsLazyPagingItems
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.ScrollbarSettings
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.Page
import org.schabi.newpipe.extractor.comments.CommentsInfoItem
import org.schabi.newpipe.extractor.stream.Description
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
import org.schabi.newpipe.ui.components.common.LoadingIndicator
import org.schabi.newpipe.ui.components.common.NoItemsMessage
import org.schabi.newpipe.ui.theme.AppTheme
import org.schabi.newpipe.ui.theme.md_theme_dark_primary
import org.schabi.newpipe.viewmodels.CommentsViewModel
import org.schabi.newpipe.viewmodels.util.Resource

Expand All @@ -52,13 +49,7 @@ private fun CommentSection(
val state = rememberLazyListState()

Surface(color = MaterialTheme.colorScheme.background) {
LazyColumnScrollbar(
state = state,
settings = ScrollbarSettings.Default.copy(
thumbSelectedColor = md_theme_dark_primary,
thumbUnselectedColor = Color.Red
)
) {
LazyColumnThemedScrollbar(state = state) {
LazyColumn(
modifier = Modifier.nestedScroll(nestedScrollInterop),
state = state
Expand Down

0 comments on commit fdf36cb

Please sign in to comment.