Skip to content

Commit

Permalink
fix(compose): fix crash when opening stream info, update compose
Browse files Browse the repository at this point in the history
  • Loading branch information
outadoc committed Feb 14, 2024
1 parent 24cc2f3 commit 2c3cb02
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
accompanist = "0.34.0"
android = "8.2.2"
coil = "2.5.0"
compose = "2023.03.00"
compose = "2024.02.00"
composeMultiplatform = "1.5.12"
emoji = "1.4.0"
kotlin = "1.9.22"
Expand Down Expand Up @@ -52,7 +52,7 @@ bignum = "com.ionspin.kotlin:bignum:0.3.9"
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
coil-core = { module = "io.coil-kt:coil", version.ref = "coil" }
coil-gif = { module = "io.coil-kt:coil-gif", version.ref = "coil" }
compose-bom = { module = "dev.chrisbanes.compose:compose-bom", version.ref = "compose" }
compose-bom = { module = "androidx.compose:compose-bom", version.ref = "compose" }
compose-foundation = { module = "androidx.compose.foundation:foundation" }
compose-material-core2 = { module = "androidx.compose.material:material" }
compose-material-core3 = { module = "androidx.compose.material3:material3" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Reply
import androidx.compose.material3.DismissDirection
import androidx.compose.material3.DismissValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface
import androidx.compose.material3.SwipeToDismiss
import androidx.compose.material3.rememberDismissState
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxState
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.material3.rememberSwipeToDismissBoxState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -32,28 +32,33 @@ fun SwipeToReply(
onDismiss: () -> Unit,
content: @Composable () -> Unit,
) {
val dismissState = rememberDismissState(
confirmValueChange = {
if (it == DismissValue.DismissedToEnd) onDismiss()
it != DismissValue.DismissedToEnd
},
)
val dismissState: SwipeToDismissBoxState =
rememberSwipeToDismissBoxState(
confirmValueChange = { value ->
if (value == SwipeToDismissBoxValue.StartToEnd) {
onDismiss()
}
value != SwipeToDismissBoxValue.StartToEnd
},
)

SwipeToDismiss(
SwipeToDismissBox(
modifier = modifier,
state = dismissState,
directions = if (enabled) setOf(DismissDirection.StartToEnd) else emptySet(),
background = {
val direction = dismissState.dismissDirection ?: return@SwipeToDismiss
if (direction != DismissDirection.StartToEnd) return@SwipeToDismiss

enableDismissFromStartToEnd = enabled,
enableDismissFromEndToStart = false,
backgroundContent = {
val scale by animateFloatAsState(
if (dismissState.targetValue == DismissValue.Default) 0.75f else 1f,
when (dismissState.targetValue) {
SwipeToDismissBoxValue.Settled -> 0.75f
else -> 1f
},
label = "Reply icon scale",
)

val haptic = LocalHapticFeedback.current
LaunchedEffect(dismissState.targetValue) {
if (dismissState.targetValue == DismissValue.DismissedToEnd) {
if (dismissState.targetValue == SwipeToDismissBoxValue.StartToEnd) {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
}
}
Expand All @@ -71,16 +76,19 @@ fun SwipeToReply(
)
}
},
dismissContent = {
val elevation = animateDpAsState(
if (dismissState.dismissDirection != null) {
4.dp
} else {
0.dp
content = {
val elevation by animateDpAsState(
targetValue = when (dismissState.targetValue) {
SwipeToDismissBoxValue.StartToEnd -> 1.dp
else -> 0.dp
},
label = "Reply item elevation",
)

Surface(shadowElevation = elevation.value) {
Surface(
tonalElevation = elevation,
shadowElevation = elevation
) {
content()
}
},
Expand Down

0 comments on commit 2c3cb02

Please sign in to comment.