Skip to content

Commit

Permalink
Support scrollable tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
ismartcoding committed May 26, 2024
1 parent 214b546 commit c9b9b82
Show file tree
Hide file tree
Showing 25 changed files with 993 additions and 709 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ismartcoding.plain.features.file

import com.ismartcoding.lib.extensions.getFilenameExtension
import com.ismartcoding.plain.data.IData
import kotlinx.datetime.Instant

Expand All @@ -17,6 +18,7 @@ data class DFile(
override var id: String
get() = path
set(value) {
path = value
}

val extension: String by lazy { path.getFilenameExtension() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fun PIconTextActionButton(
text = text,
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center,
modifier = Modifier.padding(8.dp),
modifier = Modifier.padding(horizontal = 4.dp, vertical = 8.dp),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,23 @@ public fun rememberDragSelectState(
return remember(lazyGridState) {
DragSelectState(
initialSelection = initialSelection,
gridState = lazyGridState,
gridState = { lazyGridState },
dragState = dragState,
)
}
}

@Composable
public fun rememberDragSelectState(
lazyGridState: () -> LazyGridState?,
initialSelection: List<String> = emptyList(),
): DragSelectState {
val dragState = rememberSaveable(saver = DragState.Saver) { DragState() }

return remember(lazyGridState) {
DragSelectState(
initialSelection = initialSelection,
gridState = { lazyGridState() },
dragState = dragState,
)
}
Expand All @@ -33,7 +49,7 @@ public fun rememberDragSelectState(
@Stable
class DragSelectState(
initialSelection: List<String>,
val gridState: LazyGridState,
val gridState: () -> LazyGridState?,
var dragState: DragState,
) {
var selectedIds: List<String> by mutableStateOf(initialSelection)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ismartcoding.plain.ui.base.dragselect

import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.gestures.detectDragGesturesAfterLongPress
import androidx.compose.foundation.gestures.scrollBy
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -32,7 +31,7 @@ fun Modifier.gridDragSelect(
if (state.autoScrollSpeed.value == 0f) return@LaunchedEffect

while (isActive) {
state.gridState.scrollBy(state.autoScrollSpeed.value)
state.gridState()?.scrollBy(state.autoScrollSpeed.value)
delay(10)
}
}
Expand All @@ -48,7 +47,7 @@ fun Modifier.gridDragSelect(
pointerInput(Unit) {
detectDragGestures(
onDragStart = { offset ->
state.gridState.itemIndexAtPosition(offset)?.let { startIndex ->
state.gridState()?.itemIndexAtPosition(offset)?.let { startIndex ->
val item = items.getOrNull(startIndex)
if (item != null) {
haptics?.performHapticFeedback(HapticFeedbackType.LongPress)
Expand All @@ -60,6 +59,7 @@ fun Modifier.gridDragSelect(
onDragEnd = state::stopDrag,
onDrag = { change, _ ->
state.whenDragging { dragState ->
val gridState = gridState() ?: return@whenDragging
autoScrollSpeed.value = gridState.calculateScrollSpeed(change, scrollThreshold)

val itemPosition = gridState.getItemPosition(change.position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ internal fun <IndicatorValue> ElementScrollbar(
val layoutSettings = remember(settings) {
ScrollbarLayoutSettings(
scrollbarPadding = settings.scrollbarPadding,
thumbShape = settings.thumbShape,
thumbThickness = settings.thumbThickness,
side = settings.side,
selectionActionable = settings.selectionActionable,
hideEasingAnimation = settings.hideEasingAnimation,
hideDisplacement = settings.hideDisplacement,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
package com.ismartcoding.plain.ui.base.fastscroll

/**
* Scrollbar selection modes.
*/
enum class ScrollbarSelectionActionable {
/**
* Can select scrollbar always (when visible or hidden)
*/
Always,

/**
* Can select scrollbar only when visible
*/
WhenVisible,
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
package com.ismartcoding.plain.ui.base.fastscroll

/**
* Scrollbar selection modes.
*/
enum class ScrollbarSelectionMode {
/**
* Enable selection in the whole scrollbar and thumb
*/
Full,
/**
* Enable selection in the thumb
*/
Thumb,
/**
* Disable selection
*/
Disabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ import androidx.compose.ui.unit.dp
@Stable
data class ScrollbarSettings(
val enabled: Boolean = true,
val side: ScrollbarLayoutSide = ScrollbarLayoutSide.End,
val alwaysShowScrollbar: Boolean = false,
val scrollbarPadding: Dp = 0.dp,
val thumbThickness: Dp = 12.dp,
val thumbShape: Shape = CircleShape,
val thumbMinLength: Float = 0.1f,
val selectionMode: ScrollbarSelectionMode = ScrollbarSelectionMode.Full,
val selectionActionable: ScrollbarSelectionActionable = ScrollbarSelectionActionable.Always,
val hideDelayMillis: Int = 3000,
val hideDisplacement: Dp = 15.dp,
val hideDisplacement: Dp = 0.dp,
val hideEasingAnimation: Easing = FastOutSlowInEasing,
val durationAnimationMillis: Int = 500,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ package com.ismartcoding.plain.ui.base.fastscroll.foundation

import androidx.compose.animation.core.Easing
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp
import com.ismartcoding.plain.ui.base.fastscroll.ScrollbarLayoutSide
import com.ismartcoding.plain.ui.base.fastscroll.ScrollbarSelectionActionable

@Stable
internal data class ScrollbarLayoutSettings(
val scrollbarPadding: Dp,
val thumbShape: Shape,
val thumbThickness: Dp,
val side: ScrollbarLayoutSide,
val selectionActionable: ScrollbarSelectionActionable,
val hideDisplacement: Dp,
val hideDelayMillis: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.ismartcoding.plain.ui.base.fastscroll.foundation
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
Expand Down Expand Up @@ -47,7 +49,8 @@ internal fun VerticalScrollbarLayout(
bottomStartPercent = 100
)
)
.padding(vertical = 2.dp).run { if (state.activeDraggableModifier.value) then(draggableModifier) else this },
.padding(vertical = 2.dp)
.run { if (state.activeDraggableModifier.value) then(draggableModifier) else this },
contentAlignment = Alignment.Center
) {
Icon(
Expand Down Expand Up @@ -86,7 +89,7 @@ internal fun VerticalScrollbarLayout(
val hideDisplacementPx = state.hideDisplacement.value.roundToPx()

placeableThumb.placeRelative(
x = constraints.maxWidth - placeableThumb.width + hideDisplacementPx,
x = constraints.maxWidth - placeableThumb.width + hideDisplacementPx + 8.dp.roundToPx(),
y = offset
)

Expand Down
Loading

0 comments on commit c9b9b82

Please sign in to comment.