Skip to content

Commit 7788949

Browse files
committed
Change to drawWithCache.
1 parent 0c3551f commit 7788949

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

  • Jetsnack/app/src/main/java/com/example/jetsnack/ui/snackdetail

Jetsnack/app/src/main/java/com/example/jetsnack/ui/snackdetail/SnackDetail.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import androidx.compose.runtime.setValue
5757
import androidx.compose.ui.Alignment
5858
import androidx.compose.ui.Modifier
5959
import androidx.compose.ui.draw.blur
60+
import androidx.compose.ui.draw.drawWithCache
6061
import androidx.compose.ui.geometry.Offset
6162
import androidx.compose.ui.graphics.Brush
6263
import androidx.compose.ui.graphics.TileMode
@@ -137,19 +138,23 @@ private fun Header() {
137138
label = "offset"
138139
)
139140

140-
val brushSize = 400f
141-
val brush = Brush.linearGradient(
142-
colors = brushColors,
143-
start = Offset(offset, offset),
144-
end = Offset(offset + brushSize, offset + brushSize),
145-
tileMode = TileMode.Mirror
146-
)
147141
Spacer(
148142
modifier = Modifier
149143
.height(280.dp)
150144
.fillMaxWidth()
151145
.blur(40.dp)
152-
.background(brush)
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+
}
153158

154159
)
155160
}

0 commit comments

Comments
 (0)