Skip to content

Commit 864f879

Browse files
committed
changes: add TrippyBlinders
1 parent 08947c7 commit 864f879

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package pro.jayeshseth.animations.ui.screens
2+
3+
import android.os.Build
4+
import android.os.VibrationEffect
5+
import android.os.Vibrator
6+
import androidx.compose.animation.core.Animatable
7+
import androidx.compose.animation.core.EaseInOutBounce
8+
import androidx.compose.animation.core.Spring
9+
import androidx.compose.animation.core.animateDpAsState
10+
import androidx.compose.animation.core.spring
11+
import androidx.compose.animation.core.tween
12+
import androidx.compose.foundation.background
13+
import androidx.compose.foundation.layout.Arrangement
14+
import androidx.compose.foundation.layout.Spacer
15+
import androidx.compose.foundation.layout.fillMaxWidth
16+
import androidx.compose.foundation.layout.padding
17+
import androidx.compose.foundation.layout.size
18+
import androidx.compose.foundation.lazy.rememberLazyListState
19+
import androidx.compose.foundation.shape.RoundedCornerShape
20+
import androidx.compose.material3.Card
21+
import androidx.compose.material3.CardDefaults
22+
import androidx.compose.runtime.Composable
23+
import androidx.compose.runtime.LaunchedEffect
24+
import androidx.compose.runtime.getValue
25+
import androidx.compose.runtime.remember
26+
import androidx.compose.ui.Modifier
27+
import androidx.compose.ui.graphics.Color
28+
import androidx.compose.ui.graphics.Shape
29+
import androidx.compose.ui.graphics.graphicsLayer
30+
import androidx.compose.ui.platform.LocalContext
31+
import androidx.compose.ui.unit.Dp
32+
import androidx.compose.ui.unit.dp
33+
import androidx.core.content.ContextCompat
34+
import pro.jayeshseth.commoncomponents.SystemBarAwareThemedLazyColumn
35+
36+
private const val ITEM_COUNT = 1000000
37+
38+
@Composable
39+
fun TrippyBlinders(modifier: Modifier = Modifier) {
40+
val lazyListState = rememberLazyListState()
41+
val animatedSpace by animateDpAsState(
42+
targetValue = if (lazyListState.isScrollInProgress) 4.dp else 0.dp,
43+
animationSpec = tween(1200, easing = EaseInOutBounce),
44+
label = "animated space"
45+
)
46+
val animatedPadding by animateDpAsState(
47+
targetValue = if (lazyListState.isScrollInProgress) 40.dp else 0.dp,
48+
animationSpec = tween(2800, easing = EaseInOutBounce),
49+
label = "animated padding"
50+
)
51+
val animatedShape by animateDpAsState(
52+
targetValue = if (lazyListState.isScrollInProgress) 50.dp else 0.dp,
53+
animationSpec = tween(2800, easing = EaseInOutBounce),
54+
label = "animated shape"
55+
)
56+
LaunchedEffect(Unit) {
57+
lazyListState.scrollToItem(ITEM_COUNT / 2)
58+
}
59+
SystemBarAwareThemedLazyColumn(
60+
state = lazyListState,
61+
verticalArrangement = Arrangement.spacedBy(animatedSpace),
62+
modifier = modifier
63+
.background(Color.White),
64+
systemBarColor = Color.Transparent
65+
) {
66+
items(ITEM_COUNT) {
67+
TrippyBlinderItem(
68+
index = it, shape = RoundedCornerShape(animatedShape),
69+
padding = animatedPadding
70+
)
71+
}
72+
}
73+
}
74+
75+
@Composable
76+
private fun TrippyBlinderItem(
77+
index: Int,
78+
shape: Shape,
79+
padding: Dp,
80+
modifier: Modifier = Modifier
81+
) {
82+
val animatedProgress =
83+
remember { Animatable(initialValue = 360f) }
84+
val context = LocalContext.current
85+
val vibrator = ContextCompat.getSystemService(context, Vibrator::class.java)!!
86+
LaunchedEffect(index) {
87+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
88+
vibrator.vibrate(VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK))
89+
}
90+
animatedProgress.animateTo(
91+
targetValue = 0f,
92+
animationSpec = spring(
93+
dampingRatio = Spring.DampingRatioHighBouncy,
94+
stiffness = Spring.StiffnessVeryLow
95+
)
96+
)
97+
}
98+
Card(
99+
colors = CardDefaults.cardColors(
100+
containerColor = Color.Black
101+
),
102+
shape = shape,
103+
modifier = modifier
104+
.padding(horizontal = padding)
105+
.fillMaxWidth()
106+
.graphicsLayer(
107+
shadowElevation = animatedProgress.value,
108+
shape = shape,
109+
rotationX = animatedProgress.value,
110+
)
111+
) { Spacer(Modifier.size(50.dp)) }
112+
}

0 commit comments

Comments
 (0)