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

feat: scrollbars #1479

Merged
merged 21 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fe90e5b
feat: init scrollbars
Ushie Nov 10, 2023
f5c51f1
feat: scrollbar in all scrollable pages
Ushie Nov 10, 2023
071cb30
feat: show and hide logic
Ushie Nov 10, 2023
e87454f
fix: missing paddingvalue
Ushie Nov 10, 2023
57504e2
feat: thickness, padding and colors
Ushie Nov 10, 2023
80866e2
refactor: Deduplicate code with a private function
Ushie Nov 15, 2023
9f1fb01
refactor: Create LazyColumnWithScrollbar Component
Ushie Nov 15, 2023
4d8b9f0
refactor: Create ColumnWithScrollbar Component
Ushie Nov 15, 2023
27f4f4a
fix: Apply paddingValues to Scrollbar too
Ushie Nov 15, 2023
719e9f5
Update app/src/main/java/app/revanced/manager/ui/component/Scrollbar.kt
Ushie Dec 10, 2023
dba0953
Merge remote-tracking branch 'origin/compose-dev' into feat/scrollbars
Ushie Dec 10, 2023
d4db402
Merge remote-tracking branch 'origin/compose-dev' into feat/scrollbars
Ushie Dec 10, 2023
f314561
feat: Add scrollbar to remaining screens
Ushie Dec 10, 2023
1388faa
Merge branch 'compose-dev' of https://github.com/ReVanced/revanced-ma…
Ushie Dec 25, 2023
7c57908
Merge remote-tracking branch 'origin/compose-dev' into feat/scrollbars
Ushie Dec 26, 2023
844aae8
chore: Add comment about paddingValues
Ushie Dec 26, 2023
71ca0c8
build: Bump ComposeScrollbars to v1.0.4
Ushie Dec 27, 2023
e3d6642
fix: Using incorrect parameter
Ushie Dec 27, 2023
3759479
refactor: Support LazyListState for ColumnWithScrollbar
Ushie Dec 27, 2023
e2f68f3
Revert "refactor: Support LazyListState for ColumnWithScrollbar"
Ushie Dec 29, 2023
1347f06
Merge branch 'compose-dev' into feat/scrollbars
Ushie Jan 7, 2024
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
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,7 @@ dependencies {

// Markdown
implementation(libs.markdown.renderer)

// Scrollbars
implementation(libs.scrollbars)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package app.revanced.manager.ui.component

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

@Composable
fun ColumnWithScrollbar(
modifier: Modifier = Modifier,
state: ScrollState = rememberScrollState(),
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
content: @Composable ColumnScope.() -> Unit
) {
Column(
modifier = modifier.then(Modifier.verticalScroll(state)),
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
content = content
)
Scrollbar(state, Modifier.then(modifier.padding()))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app.revanced.manager.ui.component

import androidx.compose.foundation.gestures.FlingBehavior
import androidx.compose.foundation.gestures.ScrollableDefaults
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun LazyColumnWithScrollbar(
modifier: Modifier = Modifier,
state: LazyListState = rememberLazyListState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
reverseLayout: Boolean = false,
verticalArrangement: Arrangement.Vertical =
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
userScrollEnabled: Boolean = true,
content: LazyListScope.() -> Unit
) {
LazyColumn(
modifier = modifier,
state = state,
contentPadding = contentPadding,
reverseLayout = reverseLayout,
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
flingBehavior = flingBehavior,
userScrollEnabled = userScrollEnabled,
content = content
)
Scrollbar(state, Modifier.then(modifier.padding()))
Ushie marked this conversation as resolved.
Show resolved Hide resolved
}
64 changes: 64 additions & 0 deletions app/src/main/java/app/revanced/manager/ui/component/Scrollbar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package app.revanced.manager.ui.component

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.gigamole.composescrollbars.Scrollbars
import com.gigamole.composescrollbars.ScrollbarsState
import com.gigamole.composescrollbars.config.ScrollbarsConfig
import com.gigamole.composescrollbars.config.ScrollbarsOrientation
import com.gigamole.composescrollbars.config.layercontenttype.ScrollbarsLayerContentType
import com.gigamole.composescrollbars.config.layersType.ScrollbarsLayersType
import com.gigamole.composescrollbars.config.layersType.thicknessType.ScrollbarsThicknessType
import com.gigamole.composescrollbars.config.visibilitytype.ScrollbarsVisibilityType
import com.gigamole.composescrollbars.scrolltype.ScrollbarsScrollType
import com.gigamole.composescrollbars.scrolltype.knobtype.ScrollbarsDynamicKnobType
import com.gigamole.composescrollbars.scrolltype.knobtype.ScrollbarsStaticKnobType

@Composable
fun Scrollbar(scrollState: ScrollState, modifier: Modifier = Modifier) {
Scrollbar(
ScrollbarsScrollType.Scroll(
knobType = ScrollbarsStaticKnobType.Auto(),
state = scrollState
),
modifier
)
}

@Composable
fun Scrollbar(scrollState: LazyListState, modifier: Modifier = Modifier) {
Ushie marked this conversation as resolved.
Show resolved Hide resolved
Scrollbar(
ScrollbarsScrollType.Lazy.List.Dynamic(
knobType = ScrollbarsDynamicKnobType.Auto(),
state = scrollState
),
modifier
)
}

@Composable
private fun Scrollbar(scrollType: ScrollbarsScrollType, modifier: Modifier = Modifier) {
Scrollbars(
state = ScrollbarsState(
ScrollbarsConfig(
orientation = ScrollbarsOrientation.Vertical,
paddingValues = PaddingValues(0.dp),
layersType = ScrollbarsLayersType.Wrap(ScrollbarsThicknessType.Exact(4.dp)),
knobLayerContentType = ScrollbarsLayerContentType.Default.Colored.Idle(
idleColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.35f)
),
visibilityType = ScrollbarsVisibilityType.Dynamic.Fade(
isVisibleOnTouchDown = true,
isStaticWhenScrollPossible = false
)
),
scrollType
),
modifier = modifier
)
}
Loading