Skip to content

Commit 6d8896e

Browse files
authored
Merge pull request #181 from YAPP-Github/bugfix/#180-fix-button-multiple-clicks
[BUGFIX] OrbitButton 중복 클릭 문제를 해결합니다.
2 parents 091e541 + eab19be commit 6d8896e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

core/ui/src/main/java/com/yapp/ui/component/button/OrbitButton.kt

+20-1
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@ import androidx.compose.material3.ButtonDefaults
1313
import androidx.compose.material3.Text
1414
import androidx.compose.runtime.Composable
1515
import androidx.compose.runtime.getValue
16+
import androidx.compose.runtime.mutableStateOf
1617
import androidx.compose.runtime.remember
18+
import androidx.compose.runtime.rememberCoroutineScope
19+
import androidx.compose.runtime.setValue
1720
import androidx.compose.ui.Modifier
1821
import androidx.compose.ui.graphics.Color
1922
import androidx.compose.ui.graphics.Shape
2023
import androidx.compose.ui.tooling.preview.Preview
2124
import androidx.compose.ui.unit.Dp
2225
import androidx.compose.ui.unit.dp
2326
import com.yapp.designsystem.theme.OrbitTheme
27+
import kotlinx.coroutines.delay
28+
import kotlinx.coroutines.launch
2429

2530
@Composable
2631
fun OrbitButton(
2732
label: String,
2833
modifier: Modifier = Modifier,
2934
onClick: () -> Unit,
3035
enabled: Boolean = false,
36+
debounceTime: Long = 500L,
3137
height: Dp = 54.dp,
3238
containerColor: Color = OrbitTheme.colors.main,
3339
contentColor: Color = OrbitTheme.colors.gray_900,
@@ -39,15 +45,28 @@ fun OrbitButton(
3945
) {
4046
val interactionSource = remember { MutableInteractionSource() }
4147
val isPressed = interactionSource.collectIsPressedAsState().value
48+
val coroutineScope = rememberCoroutineScope()
49+
var isClickable by remember { mutableStateOf(true) }
4250

4351
val padding by animateDpAsState(
4452
targetValue = if (isPressed) 2.dp else 0.dp,
4553
animationSpec = tween(durationMillis = 100),
4654
label = "PaddingAnimation",
4755
)
4856

57+
fun handleClick() {
58+
if (isClickable) {
59+
isClickable = false
60+
onClick()
61+
coroutineScope.launch {
62+
delay(debounceTime)
63+
isClickable = true
64+
}
65+
}
66+
}
67+
4968
Button(
50-
onClick = onClick,
69+
onClick = ::handleClick,
5170
enabled = enabled,
5271
shape = shape,
5372
colors = ButtonDefaults.buttonColors(

0 commit comments

Comments
 (0)