Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zsoltk committed Oct 8, 2023
1 parent 00e138b commit cd8ab50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.bumble.appyx.interactions.core.ui.LocalBoxScope
import com.bumble.appyx.interactions.core.ui.context.TransitionBounds
import com.bumble.appyx.interactions.core.ui.context.UiContext
import com.bumble.appyx.interactions.core.ui.property.impl.position.BiasAlignment
import com.bumble.appyx.interactions.core.ui.property.impl.position.BiasAlignment.InsideAlignment.Companion.TopStart
import com.bumble.appyx.interactions.core.ui.property.impl.position.PositionAlignment
import com.bumble.appyx.interactions.core.ui.property.impl.position.PositionOffset
import junit.framework.TestCase.assertFalse
Expand All @@ -40,12 +41,10 @@ class MutableUiStateTest {
private lateinit var coroutineScope: CoroutineScope

private fun setupTestMutableUiState(
target: PositionAlignment.Target = PositionAlignment.Target(
insideAlignment = BiasAlignment.InsideAlignment.TopStart
),
targetAlignment: PositionAlignment.Target = PositionAlignment.Target(TopStart),
targetOffset: PositionOffset.Target = PositionOffset.Target(DpOffset.Zero),
clipToBounds: Boolean = false,
containerModifier: Modifier = Modifier
.fillMaxSize(),
containerModifier: Modifier = Modifier.fillMaxSize(),
childModifier: Modifier = Modifier,
) {
composeTestRule.setContent {
Expand All @@ -62,7 +61,11 @@ class MutableUiStateTest {
uiContext = uiContext,
positionAlignment = PositionAlignment(
coroutineScope = coroutineScope,
target = target,
target = targetAlignment,
),
positionOffset = PositionOffset(
coroutineScope = coroutineScope,
target = targetOffset,
)
).apply {
updateBounds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.animation.core.spring
import androidx.compose.ui.Modifier
import com.bumble.appyx.interactions.core.ui.context.UiContext
import com.bumble.appyx.interactions.core.ui.property.impl.position.PositionAlignment
import com.bumble.appyx.interactions.core.ui.property.impl.position.PositionOffset
import com.bumble.appyx.interactions.core.ui.state.BaseMutableUiState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async
Expand All @@ -14,12 +15,14 @@ import kotlinx.coroutines.launch
class TestMutableUiState(
uiContext: UiContext,
val positionAlignment: PositionAlignment,
val positionOffset: PositionOffset,
) : BaseMutableUiState<TestTargetUiState>(
uiContext = uiContext,
motionProperties = listOf(positionAlignment),
) {
override val combinedMotionPropertyModifier: Modifier = Modifier
.then(positionAlignment.modifier)
.then(positionOffset.modifier)

override suspend fun animateTo(
scope: CoroutineScope,
Expand All @@ -33,11 +36,18 @@ class TestMutableUiState(
spring(springSpec.dampingRatio, springSpec.stiffness),
)
},
scope.async {
positionOffset.animateTo(
target.positionOffset.value,
spring(springSpec.dampingRatio, springSpec.stiffness),
)
},
).awaitAll()
}

override suspend fun snapTo(target: TestTargetUiState) {
positionAlignment.snapTo(target.positionAlignment.value)
positionOffset.snapTo(target.positionOffset.value)
}

override fun lerpTo(
Expand All @@ -48,6 +58,7 @@ class TestMutableUiState(
) {
scope.launch {
positionAlignment.lerpTo(start.positionAlignment, end.positionAlignment, fraction)
positionOffset.lerpTo(start.positionOffset, end.positionOffset, fraction)
}
}
}

0 comments on commit cd8ab50

Please sign in to comment.