File tree 1 file changed +9
-18
lines changed
Owl/app/src/main/java/com/example/owl/ui/utils
1 file changed +9
-18
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package com.example.owl.ui.utils
18
18
19
- import androidx.compose.runtime.getValue
20
- import androidx.compose.runtime.mutableStateOf
21
- import androidx.compose.runtime.remember
22
- import androidx.compose.runtime.setValue
23
19
import androidx.compose.ui.Modifier
24
- import androidx.compose.ui.composed
25
- import androidx.compose.ui.drawWithContent
20
+ import androidx.compose.ui.drawWithCache
26
21
import androidx.compose.ui.graphics.Color
27
22
import androidx.compose.ui.graphics.VerticalGradient
28
23
29
24
/* *
30
25
* A [Modifier] which draws a vertical gradient
31
26
*/
32
- fun Modifier.scrim (colors : List <Color >): Modifier = composed {
33
- var height by remember { mutableStateOf(0f ) }
34
- val gradient = remember(colors, height) {
35
- VerticalGradient (
36
- colors = colors,
37
- startY = 0f ,
38
- endY = height
39
- )
40
- }
41
- drawWithContent {
42
- drawContent()
43
- height = size.height
27
+ fun Modifier.scrim (colors : List <Color >): Modifier = drawWithCache {
28
+ // Use drawWithCache modifier to create and cache the gradient when size is known or changes.
29
+ val gradient = VerticalGradient (
30
+ colors = colors,
31
+ startY = 0f ,
32
+ endY = size.height
33
+ )
34
+ onDraw {
44
35
drawRect(brush = gradient)
45
36
}
46
37
}
You can’t perform that action at this time.
0 commit comments