|
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,11 @@ 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 |
54 | 64 | import androidx.compose.ui.layout.Layout |
55 | 65 | import androidx.compose.ui.platform.LocalDensity |
56 | 66 | import androidx.compose.ui.res.stringResource |
@@ -112,11 +122,40 @@ fun SnackDetail( |
112 | 122 |
|
113 | 123 | @Composable |
114 | 124 | private fun Header() { |
| 125 | + val brushColors = JetsnackTheme.colors.tornado1 |
| 126 | + |
| 127 | + val infiniteTransition = rememberInfiniteTransition(label = "background") |
| 128 | + val targetOffset = with(LocalDensity.current) { |
| 129 | + 1000.dp.toPx() |
| 130 | + } |
| 131 | + val offset by infiniteTransition.animateFloat( |
| 132 | + initialValue = 0f, |
| 133 | + targetValue = targetOffset, |
| 134 | + animationSpec = infiniteRepeatable( |
| 135 | + tween(50000, easing = LinearEasing), |
| 136 | + repeatMode = RepeatMode.Reverse |
| 137 | + ), |
| 138 | + label = "offset" |
| 139 | + ) |
| 140 | + |
115 | 141 | Spacer( |
116 | 142 | modifier = Modifier |
117 | 143 | .height(280.dp) |
118 | 144 | .fillMaxWidth() |
119 | | - .background(Brush.horizontalGradient(JetsnackTheme.colors.tornado1)) |
| 145 | + .blur(40.dp) |
| 146 | + .drawWithCache { |
| 147 | + val brushSize = 400f |
| 148 | + val brush = Brush.linearGradient( |
| 149 | + colors = brushColors, |
| 150 | + start = Offset(offset, offset), |
| 151 | + end = Offset(offset + brushSize, offset + brushSize), |
| 152 | + tileMode = TileMode.Mirror |
| 153 | + ) |
| 154 | + onDrawBehind { |
| 155 | + drawRect(brush) |
| 156 | + } |
| 157 | + } |
| 158 | + |
120 | 159 | ) |
121 | 160 | } |
122 | 161 |
|
|
0 commit comments