Browse Source

ImageViewer edit description onLongClick (#3009)

pull/3010/head
dima.avdeev 2 years ago committed by GitHub
parent
commit
508d265b9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MemoryScreen.kt

14
examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MemoryScreen.kt

@ -84,7 +84,7 @@ fun MemoryScreen(
Box(modifier = Modifier.background(MaterialTheme.colors.background)) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Headliner("Note")
Collapsible(picture.description)
Collapsible(picture.description, onEdit = { edit = true })
Headliner("Related memories")
RelatedMemoriesVisualizer(
pictures = remember { (pictures - picture).shuffled().take(8) },
@ -227,8 +227,9 @@ fun BoxScope.MemoryTextOverlay(picture: PictureData) {
}
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun Collapsible(s: String) {
fun Collapsible(s: String, onEdit: () -> Unit) {
val interctionSource = remember { MutableInteractionSource() }
var isCollapsed by remember { mutableStateOf(true) }
val text = if (isCollapsed) s.lines().first() + "... (see more)" else s
@ -245,10 +246,15 @@ fun Collapsible(s: String) {
dampingRatio = Spring.DampingRatioLowBouncy,
stiffness = Spring.StiffnessLow
)
)
.clickable(interactionSource = interctionSource, indication = null) {
).combinedClickable(
interactionSource = interctionSource, indication = null,
onClick = {
isCollapsed = !isCollapsed
},
onLongClick = {
onEdit()
}
)
.fillMaxWidth(),
)
}

Loading…
Cancel
Save