mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:30:43 +00:00
Prefer using graphicsLayer for better performance issue (limit number of recompositions)
This commit is contained in:
committed by
Benoit Marty
parent
579e4df9cc
commit
570be3b73b
+10
-9
@@ -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 }) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -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 = {
|
||||||
|
|||||||
Reference in New Issue
Block a user