Skip to content

Commit

Permalink
Horizontal auto-reveal scrolling for breadcrumb bar
Browse files Browse the repository at this point in the history
For #8
  • Loading branch information
kirill-grouchnikov committed Jan 14, 2022
1 parent deaec36 commit 520930c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Expand Up @@ -15,6 +15,7 @@
*/
package org.pushingpixels.aurora.component

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
Expand Down Expand Up @@ -47,6 +48,7 @@ import org.pushingpixels.aurora.theming.*
fun AuroraBreadcrumbBar(
contentModel: List<Command>,
presentationModel: BreadcrumbBarPresentationModel = BreadcrumbBarPresentationModel(),
horizontalScrollState: ScrollState = rememberScrollState(0),
modifier: Modifier
) {
val colors = AuroraSkin.colors
Expand Down Expand Up @@ -102,7 +104,6 @@ fun AuroraBreadcrumbBar(
resourceLoader = resourceLoader
)

val stateHorizontal = rememberScrollState(0)
val scope = rememberCoroutineScope()
val scrollAmount = 12.dp.value * density.density

Expand Down Expand Up @@ -146,11 +147,11 @@ fun AuroraBreadcrumbBar(
)
}
},
isActionEnabled = (stateHorizontal.value > 0),
isActionEnabled = (horizontalScrollState.value > 0),
action = {
scope.launch {
stateHorizontal.scrollTo(
(stateHorizontal.value - scrollAmount.toInt()).coerceAtLeast(0)
horizontalScrollState.scrollTo(
(horizontalScrollState.value - scrollAmount.toInt()).coerceAtLeast(0)
)
}
})
Expand Down Expand Up @@ -194,12 +195,12 @@ fun AuroraBreadcrumbBar(
)
}
},
isActionEnabled = (stateHorizontal.value < stateHorizontal.maxValue),
isActionEnabled = (horizontalScrollState.value < horizontalScrollState.maxValue),
action = {
scope.launch {
stateHorizontal.scrollTo(
(stateHorizontal.value + scrollAmount.toInt()).coerceAtMost(
stateHorizontal.maxValue
horizontalScrollState.scrollTo(
(horizontalScrollState.value + scrollAmount.toInt()).coerceAtMost(
horizontalScrollState.maxValue
)
)
}
Expand All @@ -221,7 +222,7 @@ fun AuroraBreadcrumbBar(
)
).project()

Box(modifier = Modifier.horizontalScroll(stateHorizontal)) {
Box(modifier = Modifier.horizontalScroll(horizontalScrollState)) {
Row(modifier = Modifier.fillMaxWidth().wrapContentHeight()) {
for (command in contentModel) {
AuroraCommandButton(
Expand Down
Expand Up @@ -16,6 +16,7 @@
package org.pushingpixels.aurora.demo

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -26,6 +27,7 @@ import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.rememberWindowState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.pushingpixels.aurora.component.AuroraBreadcrumbBar
import org.pushingpixels.aurora.component.model.*
Expand Down Expand Up @@ -136,9 +138,13 @@ fun AuroraWindowScope.BreadcrumbContent(auroraSkinDefinition: MutableState<Auror
}

val commandPanelContentModel = remember { mutableStateOf<CommandPanelContentModel?>(null) }
val breadcrumbBarHorizontalScrollState = rememberScrollState(0)
val onBreadcrumbItemSelected: (File) -> Unit = {
scope.launch(Dispatchers.Default) {
commandPanelContentModel.value = getCommandPanelContent(breadcrumbBarContentProvider, it)
delay(150)
breadcrumbBarHorizontalScrollState.animateScrollTo(
breadcrumbBarHorizontalScrollState.maxValue)
}
}

Expand All @@ -156,6 +162,7 @@ fun AuroraWindowScope.BreadcrumbContent(auroraSkinDefinition: MutableState<Auror
iconEnabledFilterStrategy = IconFilterStrategy.ThemedFollowText,
iconDisabledFilterStrategy = IconFilterStrategy.ThemedFollowText
),
horizontalScrollState = breadcrumbBarHorizontalScrollState,
modifier = Modifier.fillMaxWidth().auroraBackground()
.padding(horizontal = 2.dp, vertical = 4.dp)
)
Expand Down

0 comments on commit 520930c

Please sign in to comment.