• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.sample.compose.utils
2 
3 import androidx.compose.foundation.background
4 import androidx.compose.foundation.border
5 import androidx.compose.ui.Modifier
6 import androidx.compose.ui.draw.drawBehind
7 import androidx.compose.ui.geometry.Offset
8 import androidx.compose.ui.geometry.Size
9 import androidx.compose.ui.graphics.Color
10 import androidx.compose.ui.unit.Dp
11 import androidx.compose.ui.unit.dp
12 
Modifiernull13 fun Modifier.maybeBackground(color: Color?): Modifier {
14     return if (color == null) {
15         this
16     } else {
17         this.then(background(color))
18     }
19 }
20 
21 
<lambda>null22 fun Modifier.drawTopBorder(color: Color = Color.DarkGray) = this.then(drawBehind {
23     drawRect(color, Offset.Zero, size = Size(size.width, 1f))
24 })
25 
<lambda>null26 fun Modifier.drawBottomBorder(color: Color = Color.DarkGray) = this.then(drawBehind {
27     drawRect(color, Offset(0f, size.height - 1f), size = Size(size.width, 1f))
28 })
29 
30 
maybeDrawBordernull31 fun Modifier.maybeDrawBorder(draw: Boolean, color: Color = Color.Black, width: Dp = 1.dp): Modifier {
32     return if (draw) {
33         this.then(border(width, color))
34     } else {
35         this
36     }
37 }
38