Created
June 11, 2024 17:02
-
-
Save ardakazanci/567297020e19c75dd6d114486ad59fe6 to your computer and use it in GitHub Desktop.
Animated Text in Jetpack Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun AnimatedTextSwitcher() { | |
var isYellowBoxVisibility by remember { mutableStateOf(true) } | |
LaunchedEffect(Unit) { | |
while (true) { | |
delay(3000) | |
isYellowBoxVisibility = !isYellowBoxVisibility | |
} | |
} | |
Box( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.Black), | |
contentAlignment = Alignment.Center | |
) { | |
Row( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(start = 14.dp), | |
verticalAlignment = Alignment.CenterVertically | |
) { | |
Text( | |
text = "HELLO 👋 I'M", | |
fontWeight = FontWeight.Bold, | |
fontSize = 24.sp, | |
color = Color.White | |
) | |
Spacer(modifier = Modifier.width(8.dp)) | |
Box { | |
[email protected]( | |
visible = isYellowBoxVisibility, | |
enter = slideInVertically(initialOffsetY = { it }) + fadeIn( | |
animationSpec = tween( | |
durationMillis = 500, | |
easing = FastOutSlowInEasing | |
) | |
), | |
exit = slideOutVertically(targetOffsetY = { -it }) + fadeOut( | |
animationSpec = tween( | |
durationMillis = 500, | |
easing = FastOutSlowInEasing | |
) | |
) | |
) { | |
Box( | |
modifier = Modifier | |
.background(Color(0XFFCD921F)) | |
.padding(8.dp) | |
) { | |
Text( | |
text = "ANDROID DEVELOPER", | |
fontWeight = FontWeight.Bold, | |
fontSize = 24.sp, | |
color = Color.White | |
) | |
} | |
} | |
[email protected]( | |
visible = !isYellowBoxVisibility, | |
enter = slideInVertically(initialOffsetY = { it }) + fadeIn( | |
animationSpec = tween( | |
durationMillis = 500, | |
easing = FastOutSlowInEasing | |
) | |
), | |
exit = slideOutVertically(targetOffsetY = { -it }) + fadeOut( | |
animationSpec = tween( | |
durationMillis = 500, | |
easing = FastOutSlowInEasing | |
) | |
) | |
) { | |
Box( | |
modifier = Modifier | |
.background(Color(0XFFC10628)) | |
.padding(8.dp) | |
) { | |
Text( | |
text = "ARDA KAZANCI", | |
fontWeight = FontWeight.Bold, | |
fontSize = 24.sp, | |
color = Color.White | |
) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment