Prefer using graphicsLayer for better performance issue (limit number of recompositions)
This commit is contained in:
parent
8f774fc4e7
commit
667b32cdee
2 changed files with 11 additions and 10 deletions
|
|
@ -20,11 +20,10 @@ import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.RowScope
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import io.element.android.libraries.designsystem.VectorIcons
|
import io.element.android.libraries.designsystem.VectorIcons
|
||||||
|
|
@ -40,14 +39,16 @@ import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun RowScope.ReplySwipeIndicator(
|
fun RowScope.ReplySwipeIndicator(
|
||||||
swipeProgress: Float,
|
swipeProgress: () -> Float,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.align(Alignment.CenterVertically)
|
.align(Alignment.CenterVertically)
|
||||||
.padding(start = 36.dp * swipeProgress.coerceAtMost(1f))
|
.graphicsLayer {
|
||||||
.alpha(swipeProgress),
|
translationX = 36.dp.toPx() * swipeProgress().coerceAtMost(1f)
|
||||||
|
alpha = swipeProgress()
|
||||||
|
},
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
resourceId = VectorIcons.Reply,
|
resourceId = VectorIcons.Reply,
|
||||||
)
|
)
|
||||||
|
|
@ -67,10 +68,10 @@ internal fun ReplySwipeIndicatorDarkPreview() =
|
||||||
private fun ContentToPreview() {
|
private fun ContentToPreview() {
|
||||||
Column(modifier = Modifier.fillMaxWidth()) {
|
Column(modifier = Modifier.fillMaxWidth()) {
|
||||||
for (i in 0..8) {
|
for (i in 0..8) {
|
||||||
Row { ReplySwipeIndicator(swipeProgress = i / 8f) }
|
Row { ReplySwipeIndicator(swipeProgress = { i / 8f }) }
|
||||||
}
|
}
|
||||||
Row { ReplySwipeIndicator(swipeProgress = 1.5f) }
|
Row { ReplySwipeIndicator(swipeProgress = { 1.5f }) }
|
||||||
Row { ReplySwipeIndicator(swipeProgress = 2f) }
|
Row { ReplySwipeIndicator(swipeProgress = { 2f }) }
|
||||||
Row { ReplySwipeIndicator(swipeProgress = 3f) }
|
Row { ReplySwipeIndicator(swipeProgress = { 3f }) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ fun TimelineItemEventRow(
|
||||||
SwipeToDismiss(
|
SwipeToDismiss(
|
||||||
state = dismissState,
|
state = dismissState,
|
||||||
background = {
|
background = {
|
||||||
ReplySwipeIndicator(dismissState.toSwipeProgress())
|
ReplySwipeIndicator({ dismissState.toSwipeProgress() })
|
||||||
},
|
},
|
||||||
directions = setOf(DismissDirection.StartToEnd),
|
directions = setOf(DismissDirection.StartToEnd),
|
||||||
dismissContent = {
|
dismissContent = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue