-
Notifications
You must be signed in to change notification settings - Fork 9
/
QuackBorder.kt
83 lines (78 loc) · 2.42 KB
/
QuackBorder.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Designed and developed by 2022 SungbinLand, Team Duckie
*
* Licensed under the MIT.
* Please see full license: https://github.com/duckie-team/quack-quack-android/blob/master/LICENSE
*/
package team.duckie.quackquack.ui.border
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.BorderStroke
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import team.duckie.quackquack.ui.animation.QuackAnimationSpec
import team.duckie.quackquack.ui.color.QuackColor
import team.duckie.quackquack.ui.color.animateQuackColorAsState
/**
* [BorderStroke] 에서 [BorderStroke.brush] 값을 [QuackColor] 로 받기 위한
* [BorderStroke] 의 wrapper 클래스 입니다.
*
* @param width border 의 굵기
* @param color border 의 색상
*/
// 기본 값으로 정해진게 없기에 internal constructor
@Immutable
internal class QuackBorder(
val width: Dp = 1.dp,
val color: QuackColor,
) {
/**
* [color] 를 [Brush] 로 변환합니다.
*
* @return [color] 를 [Brush] 로 변환한 값
*/
val brush = SolidColor(
value = color.composeColor,
)
/**
* [QuackBorder] 를 [BorderStroke] 로 변환합니다.
*
* @return 변환된 [BorderStroke]
*/
@Stable
fun asComposeBorder() = BorderStroke(
width = width,
brush = brush,
)
}
/**
* [QuackBorder] 의 변화에 애니메이션을 적용합니다.
* [QuackBorder.width] 와 [QuackBorder.color] 모두 애니메이션이 적용됩니다.
*
* animationSpec 으로 항상 [QuackAnimationSpec] 을 사용합니다.
*
* @param targetValue 애니메이션을 적용할 [QuackBorder]
*
* @return 애니메이션이 적용되고 있는 [QuackBorder] 객체
*/
@Composable
internal fun animatedQuackBorderAsState(
targetValue: QuackBorder,
): QuackBorder {
val widthAnimationState by animateDpAsState(
targetValue = targetValue.width,
animationSpec = QuackAnimationSpec(),
)
val colorAnimationState by animateQuackColorAsState(
targetValue = targetValue.color,
)
return QuackBorder(
width = widthAnimationState,
color = colorAnimationState,
)
}