Skip to content

Commit

Permalink
Give the control of the arrow animation to itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Drjacky committed Jun 16, 2024
1 parent d3afa93 commit 94a6c4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.graphics.Color
Expand All @@ -32,9 +36,17 @@ import app.web.drjackycv.presentation.products.choose.CirclePosition
@Suppress("MagicNumber")
@Composable
fun ChooseArrowAnimation(
circleState: CirclePosition,
modifier: Modifier = Modifier,
) {
var circleState by remember { mutableStateOf(CirclePosition.Start) }

LaunchedEffect(Unit) {
circleState = when (circleState) {
CirclePosition.Start -> CirclePosition.Finish
CirclePosition.Finish -> CirclePosition.Start
}
}

val offsetAnimation: Dp by animateDpAsState(
label = "offsetAnimation",
targetValue = if (circleState == CirclePosition.Start) 0.dp else 100.dp,
Expand Down Expand Up @@ -128,6 +140,5 @@ fun ChooseArrowAnimation(
private fun ChooseArrowAnimationPreview() {
ChooseArrowAnimation(
modifier = Modifier,
circleState = CirclePosition.Start
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import androidx.compose.material.Button
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -56,7 +51,7 @@ fun ChooseView(
) {
val (chooseAnimation, rxButton, coroutineButton) = createRefs()

SetupAndRunChooseArrowAnimation(
ChooseArrowAnimation(
modifier = Modifier
.constrainAs(chooseAnimation) {
start.linkTo(parent.start, margin = 20.dp)
Expand Down Expand Up @@ -104,24 +99,6 @@ fun ChooseView(
)
}

@Composable
fun SetupAndRunChooseArrowAnimation(
modifier: Modifier = Modifier,
) {
var circleState by remember { mutableStateOf(CirclePosition.Start) }

ChooseArrowAnimation(
modifier = modifier,
circleState = circleState
)
LaunchedEffect(Unit) {
circleState = when (circleState) {
CirclePosition.Start -> CirclePosition.Finish
CirclePosition.Finish -> CirclePosition.Start
}
}
}

@Composable //TODO
fun PathButton(
name: String,
Expand Down

0 comments on commit 94a6c4a

Please sign in to comment.