๐์ฐธ๊ณ ์๋ฃ
์ค๋์ BMI ๊ณ์ฐ๊ธฐ ์ฑ์ ์ ๋๋ฉ์ด์
์ ์ ์ฉํด๋ณด์๋ค.
Jetpack Compose๋ ๋ค์ํ ์ ๋๋ฉ์ด์
API๋ฅผ ์ ๊ณตํ๋ค.
-> ๊ตฌํํ๊ณ ์ ํ๋ ์ ๋๋ฉ์ด์
์ ๋ฐ๋ผ ์ ์ ํ ์ ๋๋ฉ์ด์
API ์ ํํด ์ฌ์ฉํ๋ค.
๐์ฐธ๊ณ ์๋ฃ
rememberInfiniteTransition
์ฌ์ฉ@Composable
fun PulsingImage(
@DrawableRes imageId: Int
) {
val infiniteTransition = rememberInfiniteTransition(label = "pulse_image")
val scale = infiniteTransition.animateFloat(
label = "pulse_image",
initialValue = 0.3F,
targetValue = 0.6F,
animationSpec = infiniteRepeatable(
animation = tween(1000),
repeatMode = RepeatMode.Reverse
)
)
Image(
painter = painterResource(id = imageId),
contentDescription = "",
modifier = Modifier
.graphicsLayer(
scaleX = scale.value,
scaleY = scale.value
)
.clipToBounds()
)
}
์ฐธ๊ณ ์๋ฃ
updateTransition
๊ณผ MutableTransitionState
์ฌ์ฉcurrentState
, targetState
๋ฅผ ๊ฐ์งTransformOrigin
์ ์ฌ์ฉํด ์ด๋ฏธ์ง ํ์ ์ถ ์ค์ enum class ResultPanelState {
BEFORE,
AFTER
}
@Composable
fun ResultPanel(
modifier: Modifier = Modifier,
targetDegree: Float
) {
val resultPanelState = remember { MutableTransitionState(ResultPanelState.BEFORE) }
resultPanelState.targetState = ResultPanelState.AFTER
val panelTransition = updateTransition(
transitionState = resultPanelState, label = "rotate_panel"
)
val panelDegree = panelTransition.animateFloat(
label = "rotate_panel",
transitionSpec = { tween(1500) },
targetValueByState = { state ->
when (state) {
ResultPanelState.BEFORE -> -225F
ResultPanelState.AFTER -> targetDegree
}
}
)
Box(
modifier = modifier
.width(150.dp)
.height(150.dp)
) {
Image(
painter = painterResource(id = R.drawable.result_panel),
contentDescription = "",
modifier = modifier.align(Alignment.BottomCenter)
)
Image(
painter = painterResource(id = R.drawable.result_panel_arrow),
contentDescription = "",
modifier = modifier
.align(Alignment.BottomCenter)
.padding(start = 32.dp)
.scale(0.5F)
.graphicsLayer(
rotationZ = panelDegree.value,
transformOrigin = TransformOrigin(
pivotFractionX = 0.26F,
pivotFractionY = 0.44F
)
)
)
}
}
LaunchedEffect
์ฌ์ฉenum class RotationState {
BEFORE,
AFTER
}
@Composable
fun RotatingText(
text: String,
textColor: Int
) {
val textRotationState = remember { MutableTransitionState(RotationState.BEFORE) }
LaunchedEffect(Unit) {
textRotationState.targetState = RotationState.AFTER
}
val rotationTransition = updateTransition(
transitionState = textRotationState,
label = "rotate_text"
)
val rotation = rotationTransition.animateFloat(
label = "rotate_text",
transitionSpec = {
tween(3000)
},
targetValueByState = { state ->
when (state) {
RotationState.BEFORE -> 360F
RotationState.AFTER -> 0F
}
}
)
Text(
text = text,
color = Color(textColor),
modifier = Modifier
.graphicsLayer(
rotationX = rotation.value,
rotationY = rotation.value
)
.clickable {
with(textRotationState) {
targetState =
if (currentState == RotationState.AFTER) RotationState.BEFORE
else RotationState.AFTER
}
}
)
}