|
17 | 17 | package com.example.jetsnack.ui.snackdetail |
18 | 18 |
|
19 | 19 | import android.content.res.Configuration |
| 20 | +import androidx.compose.animation.core.LinearEasing |
| 21 | +import androidx.compose.animation.core.RepeatMode |
| 22 | +import androidx.compose.animation.core.animateFloat |
| 23 | +import androidx.compose.animation.core.infiniteRepeatable |
| 24 | +import androidx.compose.animation.core.rememberInfiniteTransition |
| 25 | +import androidx.compose.animation.core.tween |
20 | 26 | import androidx.compose.foundation.ScrollState |
21 | 27 | import androidx.compose.foundation.background |
22 | 28 | import androidx.compose.foundation.clickable |
@@ -50,7 +56,12 @@ import androidx.compose.runtime.remember |
50 | 56 | import androidx.compose.runtime.setValue |
51 | 57 | import androidx.compose.ui.Alignment |
52 | 58 | import androidx.compose.ui.Modifier |
| 59 | +import androidx.compose.ui.draw.blur |
| 60 | +import androidx.compose.ui.draw.drawWithCache |
| 61 | +import androidx.compose.ui.geometry.Offset |
53 | 62 | import androidx.compose.ui.graphics.Brush |
| 63 | +import androidx.compose.ui.graphics.TileMode |
| 64 | +import androidx.compose.ui.graphics.drawscope.rotate |
54 | 65 | import androidx.compose.ui.layout.Layout |
55 | 66 | import androidx.compose.ui.platform.LocalDensity |
56 | 67 | import androidx.compose.ui.res.stringResource |
@@ -112,11 +123,35 @@ fun SnackDetail( |
112 | 123 |
|
113 | 124 | @Composable |
114 | 125 | private fun Header() { |
| 126 | + val brushColors = JetsnackTheme.colors.tornado1 |
| 127 | + |
| 128 | + val infiniteTransition = rememberInfiniteTransition(label = "background") |
| 129 | + val targetOffset = with (LocalDensity.current) { |
| 130 | + 1000.dp.toPx() |
| 131 | + } |
| 132 | + val offset by infiniteTransition.animateFloat( |
| 133 | + initialValue = 0f, |
| 134 | + targetValue = targetOffset, |
| 135 | + animationSpec = infiniteRepeatable(tween(50000, easing = LinearEasing), |
| 136 | + repeatMode = RepeatMode.Reverse |
| 137 | + ), |
| 138 | + label = "offset" |
| 139 | + ) |
| 140 | + |
| 141 | + val brushSize = 400f |
| 142 | + val brush = Brush.linearGradient( |
| 143 | + colors = brushColors, |
| 144 | + start = Offset(offset, offset), |
| 145 | + end = Offset( offset + brushSize, offset + brushSize), |
| 146 | + tileMode = TileMode.Mirror |
| 147 | + ) |
115 | 148 | Spacer( |
116 | 149 | modifier = Modifier |
117 | 150 | .height(280.dp) |
118 | 151 | .fillMaxWidth() |
119 | | - .background(Brush.horizontalGradient(JetsnackTheme.colors.tornado1)) |
| 152 | + .blur(40.dp) |
| 153 | + .background(brush) |
| 154 | + |
120 | 155 | ) |
121 | 156 | } |
122 | 157 |
|
|
0 commit comments