Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Feb 1, 2024
1 parent b8465ac commit dd02811
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.absoluteOffset
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -60,14 +59,19 @@ fun SwipeableActionsBox(
}
}

val backgroundColor: Color by animateColorAsState(
when {
state.swipedAction != null -> state.swipedAction!!.value.background
!state.hasCrossedSwipeThreshold() -> backgroundUntilSwipeThreshold
state.visibleAction != null -> state.visibleAction!!.value.background
else -> Color.Transparent
}
)
val backgroundColor = when {
state.swipedAction != null -> state.swipedAction!!.value.background
!state.hasCrossedSwipeThreshold() -> backgroundUntilSwipeThreshold
state.visibleAction != null -> state.visibleAction!!.value.background
else -> Color.Transparent
}
val animatedBackgroundColor: Color = if (state.layoutWidth == 0) {
// Use the current color immediately because paparazzi can only capture the 1st frame.
// https://github.com/cashapp/paparazzi/issues/1261
backgroundColor
} else {
animateColorAsState(backgroundColor).value
}

val scope = rememberCoroutineScope()
Box(
Expand All @@ -93,7 +97,7 @@ fun SwipeableActionsBox(
modifier = Modifier.matchParentSize(),
action = action,
offset = state.offset.value,
backgroundColor = backgroundColor,
backgroundColor = animatedBackgroundColor,
content = { action.value.icon() }
)
}
Expand Down

0 comments on commit dd02811

Please sign in to comment.