-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#277 [Feat] 컴포즈 SingleEventHandler 구현 및 적용 #317
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
작업하시느라 고생하셨습니다!
저도 필요할 때 사용해야겠네요~!! 👍
코맨트 확인해주세요!
...main/java/hous/release/android/presentation/our_rules/component/update/RulePhotoStatusBar.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테코까지 구웃~~ 👍
@@ -33,7 +33,7 @@ fun RuleAddPhotoButton( | |||
) { | |||
val focusManager = LocalFocusManager.current | |||
Row( | |||
modifier = Modifier.clickable( | |||
modifier = Modifier.clickableSingle( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨숨다
SingleEventArea { cutter -> | ||
FloatingActionButton( | ||
onClick = { cutter.handle(onClick) }, | ||
backgroundColor = HousBlue, | ||
contentColor = HousWhite, | ||
modifier = Modifier.size(92.dp) | ||
.padding(16.dp) | ||
) { | ||
Icon( | ||
imageVector = ImageVector.vectorResource(id = R.drawable.ic_plus), | ||
contentDescription = "Add" | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 이런식으로 쓰는군요 !!
@OptIn(ExperimentalTime::class) | ||
internal class ThrottledDurationStrategy : SingleEventHandleStrategy { | ||
private val currentTime: TimeMark get() = TimeSource.Monotonic.markNow() | ||
private val throttleDuration: Duration = 300.milliseconds | ||
private lateinit var lastEventTime: TimeMark | ||
|
||
override fun handle(event: () -> Unit) { | ||
if (::lastEventTime.isInitialized.not() || (lastEventTime + throttleDuration).hasPassedNow()) { | ||
event() | ||
} | ||
lastEventTime = currentTime | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow
관련 이슈
작업한 내용
designsystem/util
에 SingleEventHandler 구현designsystem/modifier
에 ClickableSingle 구현designsystem/component/user_interaction
에 SingleEventArea 컴포저블 구현PR 포인트
1. SingleEventHandler
여러 번 클릭 이벤트를 막아주는 SingleEventHandler입니다.
마지막 이벤트가 발생한 시간이 300ms이 넘어야 이벤트가 발생할 수 있도록 하였습니다.
SingleEventHandlerImpl
를 구현할 때 kotlin.time api를 사용했습니다.기존
System.currentTimeMillis()
방식보다 훨씬 코드 조작하기도 편하고, 나중에 time이나 Date 관련해서 작업하신다면 적극 이용해보세요!!2. 사용법
SingleEventHandler를 기반으로 Modifier 확장함수와 composable을 만들었습니다.
참고 블로그 - How to prevent multiple clicks in Android Jetpack Compose.
3. 추가 리팩토링
SingleEventHandler를 사용하는 곳이 사용처마다 달라질 수도 있다고 생각이 들어 전략패턴을 사용하여 변경했습니다 ! c2de285
4. 테스트
솔직히 SingleEventHandler는 굳이 테스트 안해도 될 것 같습니다만.. 올만에 mockking해보고 싶어서 했습니다 :D