|
1 | 1 | package com.texthip.thip.ui.common.bottomsheet |
2 | 2 |
|
3 | | -import androidx.compose.animation.core.Animatable |
4 | | -import androidx.compose.animation.core.tween |
5 | | -import androidx.compose.foundation.background |
6 | 3 | import androidx.compose.foundation.clickable |
7 | | -import androidx.compose.foundation.gestures.detectVerticalDragGestures |
8 | | -import androidx.compose.foundation.interaction.MutableInteractionSource |
9 | 4 | import androidx.compose.foundation.layout.Arrangement |
10 | | -import androidx.compose.foundation.layout.Box |
11 | 5 | import androidx.compose.foundation.layout.Column |
12 | 6 | import androidx.compose.foundation.layout.Spacer |
13 | | -import androidx.compose.foundation.layout.fillMaxSize |
14 | 7 | import androidx.compose.foundation.layout.fillMaxWidth |
15 | 8 | import androidx.compose.foundation.layout.height |
16 | | -import androidx.compose.foundation.layout.offset |
17 | 9 | import androidx.compose.foundation.layout.padding |
18 | | -import androidx.compose.foundation.shape.RoundedCornerShape |
19 | 10 | import androidx.compose.material3.HorizontalDivider |
20 | 11 | import androidx.compose.material3.Text |
21 | 12 | import androidx.compose.runtime.Composable |
22 | | -import androidx.compose.runtime.LaunchedEffect |
23 | | -import androidx.compose.runtime.getValue |
24 | | -import androidx.compose.runtime.mutableFloatStateOf |
25 | | -import androidx.compose.runtime.mutableStateOf |
26 | | -import androidx.compose.runtime.remember |
27 | | -import androidx.compose.runtime.rememberCoroutineScope |
28 | | -import androidx.compose.runtime.setValue |
29 | | -import androidx.compose.ui.Alignment |
30 | 13 | import androidx.compose.ui.Modifier |
31 | | -import androidx.compose.ui.graphics.Color |
32 | | -import androidx.compose.ui.input.pointer.pointerInput |
33 | 14 | import androidx.compose.ui.res.stringResource |
34 | 15 | import androidx.compose.ui.tooling.preview.Preview |
35 | 16 | import androidx.compose.ui.unit.dp |
36 | | -import androidx.compose.ui.zIndex |
37 | 17 | import com.texthip.thip.R |
| 18 | +import com.texthip.thip.ui.group.room.mock.MenuBottomSheetItem |
38 | 19 | import com.texthip.thip.ui.theme.ThipTheme.colors |
39 | 20 | import com.texthip.thip.ui.theme.ThipTheme.typography |
40 | | -import kotlinx.coroutines.launch |
41 | | - |
42 | | -data class MenuBottomSheetItem( |
43 | | - val text: String, |
44 | | - val color: Color = Color.White, |
45 | | - val onClick: () -> Unit, |
46 | | -) |
47 | 21 |
|
48 | 22 | @Composable |
49 | 23 | fun MenuBottomSheet( |
50 | 24 | items: List<MenuBottomSheetItem>, |
51 | 25 | onDismiss: () -> Unit |
52 | 26 | ) { |
53 | | - val scope = rememberCoroutineScope() |
54 | | - val animatableOffset = remember { Animatable(300f) } // 시작 위치 아래 |
55 | | - var offsetY by remember { mutableFloatStateOf(0f) } |
56 | | - var isDismissing by remember { mutableStateOf(false) } |
57 | | - |
58 | | - // 등장 애니메이션 |
59 | | - LaunchedEffect(Unit) { |
60 | | - animatableOffset.animateTo( |
61 | | - targetValue = 0f, |
62 | | - animationSpec = tween(durationMillis = 300) |
63 | | - ) |
64 | | - } |
65 | | - |
66 | | - // 바깥 클릭 감지 |
67 | | - Box( |
68 | | - modifier = Modifier |
69 | | - .fillMaxSize() |
70 | | - .clickable( |
71 | | - indication = null, |
72 | | - interactionSource = remember { MutableInteractionSource() } |
73 | | - ) { |
74 | | - if (!isDismissing) { |
75 | | - isDismissing = true |
76 | | - scope.launch { |
77 | | - animatableOffset.animateTo(300f, tween(300)) |
78 | | - onDismiss() |
79 | | - } |
80 | | - } |
| 27 | + CustomBottomSheet( |
| 28 | + onDismiss = onDismiss, |
| 29 | + ) { |
| 30 | + items.forEachIndexed { index, item -> |
| 31 | + if (index > 0) { |
| 32 | + Spacer(modifier = Modifier.height(8.dp)) |
| 33 | + HorizontalDivider(modifier = Modifier.height(1.dp), color = colors.Grey03) |
| 34 | + Spacer(modifier = Modifier.height(8.dp)) |
81 | 35 | } |
82 | | - .zIndex(1f) // 다른 컴포넌트 위에 뜨도록 |
83 | | - ) |
84 | 36 |
|
85 | | - |
86 | | - // BottomSheet 본체 |
87 | | - Box( |
88 | | - modifier = Modifier |
89 | | - .fillMaxSize() |
90 | | - .zIndex(2f), // 시트가 배경보다 위에 뜨도록 |
91 | | - contentAlignment = Alignment.BottomCenter |
92 | | - ) { |
93 | | - Box( |
94 | | - modifier = Modifier |
95 | | - .fillMaxWidth() |
96 | | - .offset(y = (offsetY + animatableOffset.value).dp) |
97 | | - .background( |
98 | | - color = colors.DarkGrey, |
99 | | - shape = RoundedCornerShape(topEnd = 12.dp, topStart = 12.dp) |
100 | | - ) |
101 | | - .padding(20.dp) |
102 | | - .pointerInput(Unit) { |
103 | | - detectVerticalDragGestures( |
104 | | - onVerticalDrag = { _, dragAmount -> |
105 | | - if (dragAmount > 0) { |
106 | | - offsetY += dragAmount / 2 // 아래로 드래그할 때만 적용 |
107 | | - } |
108 | | - }, |
109 | | - onDragEnd = { |
110 | | - if (offsetY > 100f && !isDismissing) { |
111 | | - isDismissing = true |
112 | | - scope.launch { |
113 | | - animatableOffset.animateTo(300f, tween(300)) |
114 | | - onDismiss() |
115 | | - } |
116 | | - } else { |
117 | | - offsetY = 0f |
118 | | - } |
| 37 | + Column( |
| 38 | + modifier = Modifier |
| 39 | + .height(50.dp) |
| 40 | + .padding(horizontal = 12.dp, vertical = 8.dp), |
| 41 | + verticalArrangement = Arrangement.Center |
| 42 | + ) { |
| 43 | + Text( |
| 44 | + text = item.text, |
| 45 | + style = typography.menu_m500_s16_h24, |
| 46 | + color = item.color, |
| 47 | + modifier = Modifier |
| 48 | + .fillMaxWidth() |
| 49 | + .clickable { |
| 50 | + item.onClick() |
| 51 | + onDismiss() |
119 | 52 | } |
120 | | - ) |
121 | | - } |
122 | | - .clickable(enabled = true) {} // 내부 클릭 무시되지 않도록 |
123 | | - ) { |
124 | | - Column(modifier = Modifier.fillMaxWidth()) { |
125 | | - items.forEachIndexed { index, item -> |
126 | | - if (index > 0) { |
127 | | - Spacer(modifier = Modifier.height(8.dp)) |
128 | | - HorizontalDivider(modifier = Modifier.height(1.dp), color = colors.Grey03) |
129 | | - Spacer(modifier = Modifier.height(8.dp)) |
130 | | - } |
131 | | - |
132 | | - Column( |
133 | | - modifier = Modifier |
134 | | - .height(50.dp) |
135 | | - .padding(horizontal = 12.dp, vertical = 8.dp), |
136 | | - verticalArrangement = Arrangement.Center |
137 | | - ) { |
138 | | - Text( |
139 | | - text = item.text, |
140 | | - style = typography.menu_m500_s16_h24, |
141 | | - color = item.color, |
142 | | - modifier = Modifier |
143 | | - .fillMaxWidth() |
144 | | - .clickable { |
145 | | - item.onClick() |
146 | | - onDismiss() |
147 | | - } |
148 | | - ) |
149 | | - } |
150 | | - } |
| 53 | + ) |
151 | 54 | } |
152 | 55 | } |
153 | 56 | } |
|
0 commit comments