-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d40ff98
commit 1a70e36
Showing
3 changed files
with
90 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...mposeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/controls/PillDragHandle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.stadiamaps.ferrostar.composeui.views.controls | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.rounded.KeyboardArrowUp | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.semantics.Role | ||
import androidx.compose.ui.semantics.onClick | ||
import androidx.compose.ui.semantics.role | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun PillDragHandle( | ||
isExpanded: Boolean, | ||
modifier: Modifier = Modifier.fillMaxWidth(), | ||
iconTintColor: Color = MaterialTheme.colorScheme.onSurface, | ||
toggle: () -> Unit = {} | ||
) { | ||
val handleHeight = if (isExpanded) 36.dp else 4.dp | ||
Box(modifier = modifier.height(handleHeight).clickable(onClick = toggle)) { | ||
if (isExpanded) { | ||
Icon( | ||
Icons.Rounded.KeyboardArrowUp, | ||
modifier = Modifier.align(Alignment.Center), | ||
contentDescription = "Show upcoming maneuvers", | ||
tint = iconTintColor) | ||
} else { | ||
Box( | ||
modifier = | ||
Modifier.align(Alignment.Center) | ||
.height(handleHeight) | ||
.width(24.dp) | ||
.background(iconTintColor, RoundedCornerShape(6.dp)) | ||
.semantics { | ||
role = Role.Button | ||
onClick(label = "Hide upcoming maneuvers") { | ||
toggle() | ||
true | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun PreviewPillDragHandleCollapsed() { | ||
PillDragHandle(isExpanded = false, iconTintColor = Color.White) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun PreviewPillDragHandleExpanded() { | ||
PillDragHandle(isExpanded = true, iconTintColor = Color.White) | ||
} |