Skip to content

Added Text Loading animation #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions app/src/main/java/dev/baseio/composeplayground/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import android.view.Window
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
Expand All @@ -28,9 +34,14 @@ import dev.baseio.composeplayground.ui.animations.anmolverma.GramophoneDisc
import dev.baseio.composeplayground.ui.animations.anmolverma.ShootingStarsAnimation
import dev.baseio.composeplayground.ui.animations.anmolverma.SlackAnimation
import dev.baseio.composeplayground.ui.animations.anmolverma.googleio2022.GoogleIO
import dev.baseio.composeplayground.ui.animations.anmolverma.loadingindicators.LoadingAnimation
import dev.baseio.composeplayground.ui.animations.anmolverma.loadingindicators.LoadingIndicator
import dev.baseio.composeplayground.ui.animations.anmolverma.loadingindicators.Size
import dev.baseio.composeplayground.ui.animations.anmolverma.loadingindicators.Speed
import dev.baseio.composeplayground.ui.animations.anmolverma.planetarysystem.PlanetarySystem
import dev.baseio.composeplayground.ui.animations.anmolverma.pulltorefresh.PullToRefreshOne
import dev.baseio.composeplayground.ui.theme.ComposePlaygroundTheme
import dev.baseio.composeplayground.ui.theme.Typography

class MainActivity : ComponentActivity() {
@OptIn(ExperimentalPagerApi::class)
Expand Down Expand Up @@ -72,7 +83,7 @@ class MainActivity : ComponentActivity() {
) {
HorizontalPager(
modifier = Modifier.fillMaxSize(),
count = 18, state = pagerState,
count = 19, state = pagerState,
) { page ->
// Our page content
when (page) {
Expand Down Expand Up @@ -133,7 +144,7 @@ class MainActivity : ComponentActivity() {
SlackAnimation()
}
2 -> {
GramophoneDisc()
// GramophoneDisc()
}
14 -> {
Box(Modifier.fillMaxSize()) {
Expand All @@ -150,6 +161,36 @@ class MainActivity : ComponentActivity() {
BellAnimation(Modifier.align(Alignment.Center))
}
}
18 -> {
Column(
Modifier
.verticalScroll(rememberScrollState())
.padding(24.dp)){
LoadingAnimation.values().forEach { loadingAnim->
Column(
Modifier) {
Column {
Text(text = "Sizes", style = Typography.subtitle1.copy(fontWeight = FontWeight.Bold))

Size.values().forEach { size ->
Column(Modifier.border(1.dp, androidx.compose.ui.graphics.Color.Black).padding(8.dp)) {
LoadingIndicator(loadingAnim, size.factor, Speed.normal.factor)
Text(size.toString(), style = Typography.caption)
}
}
}
Divider()
Text(text = "Speeds", style = Typography.subtitle1.copy(fontWeight = FontWeight.Bold))
Speed.values().forEach { speed ->
Column(Modifier.border(1.dp, androidx.compose.ui.graphics.Color.Black).padding(8.dp)) {
LoadingIndicator(loadingAnim, Size.medium.factor, speed.factor)
Text(speed.toString(), style = Typography.caption)
}
}
}
}
}
}
}
}
HorizontalPagerIndicator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ fun LoadingIndicator(
speed: Double, color: Color = Color.Black
) {
when (animation) {
LoadingAnimation.text -> LoadingText(color = color, size = size, speed = speed)
LoadingAnimation.threeBalls -> LoadingThreeBalls(color = color, size = size, speed = speed)
LoadingAnimation.threeBallsRotation -> LoadingThreeBallsRotation(
LoadingAnimation.threeBallsRotation -> LoadingThreeBallsRotation(
color = color,
size = size,
speed = speed
)
LoadingAnimation.threeBallsBouncing -> LoadingThreeBallsBouncing(
LoadingAnimation.threeBallsBouncing -> LoadingThreeBallsBouncing(
color = color,
size = size,
speed = speed
Expand Down Expand Up @@ -77,8 +78,10 @@ fun LoadingIndicator(
)
LoadingAnimation.bar -> LoadingBar(color = color, size = size, speed = speed)
LoadingAnimation.barStripes -> LoadingBarStripes(color = color, size = size, speed = speed)
LoadingAnimation.text -> LoadingText(color = color, size = size, speed = speed)
LoadingAnimation.heart -> LoadingHeart(color = color, size = size, speed = speed)*/
else -> {
// Do Nothing
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ fun LoadingPreviewView() {
}
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package dev.baseio.composeplayground.ui.animations.anmolverma.loadingindicators

import androidx.compose.animation.core.animateIntAsState
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.offset
import androidx.compose.material.Text
import androidx.compose.material.Typography
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

@Composable
fun LoadingText(color: Color = Color.Black, size: Int = 50, speed: Double = 0.5) {

val loadingText = "Loading..."
val maxCounter = loadingText.length
var counter by remember {
mutableStateOf(0)
}

val scope = rememberCoroutineScope()

LaunchedEffect(key1 = speed, block = {
scope.launch {
while (true) {
delay(speed.times(800).toLong())
counter = if (counter == (maxCounter - 1)) 0 else counter + 1
}
}
})

Row(Modifier, verticalAlignment = Alignment.CenterVertically) {
loadingText.forEachIndexed { index, c ->
LoadingCharAtString(size = size, counter = counter, index = index, color = color,text = c)
}
}
}

@Composable
fun LoadingCharAtString(
size: Int,
counter: Int,
index: Int,
color: Color,
text : Char
) {
val verticalCharAnimation = animateIntAsState(targetValue = if (counter == index) -size / 10 else 0)

Text(
modifier = Modifier.offset(
x = 0.dp,
y = verticalCharAnimation.value.dp
),
text = text.toString(),
color = color,
fontSize = size.sp
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ fun LoadingThreeBalls(color: Color = Color.Black, size: Int = 50, speed: Double
EachCircle(size, counter, index, color)
}
}

}

@Composable
Expand Down