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. 16
      examples/imageviewer/shared/src/commonMain/kotlin/example/imageviewer/view/MemoryScreen.kt

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

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

Loading…
Cancel
Save