Skip to content
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

Merged
merged 13 commits into from
Sep 19, 2023

Conversation

murjune
Copy link
Member

@murjune murjune commented Sep 15, 2023

관련 이슈

작업한 내용

  • designsystem/util 에 SingleEventHandler 구현
  • designsystem/modifier 에 ClickableSingle 구현
  • designsystem/component/user_interaction에 SingleEventArea 컴포저블 구현
  • SingleEventHandler 테스트
  • ThrottledDurationStrategy 테스트

PR 포인트

1. SingleEventHandler

여러 번 클릭 이벤트를 막아주는 SingleEventHandler입니다.
마지막 이벤트가 발생한 시간이 300ms이 넘어야 이벤트가 발생할 수 있도록 하였습니다.
SingleEventHandlerImpl를 구현할 때 kotlin.time api를 사용했습니다.
기존 System.currentTimeMillis() 방식보다 훨씬 코드 조작하기도 편하고, 나중에 time이나 Date 관련해서 작업하신다면 적극 이용해보세요!!

2. 사용법

SingleEventHandler를 기반으로 Modifier 확장함수와 composable을 만들었습니다.

  • SingleEventArea은 0406da88337ceb 을 보시면 사용법을 알 수 있습니다.
  • clickableSingle 은 아래와 같이 사용하시면 됩니다 fffc2d6
    image

참고 블로그 - How to prevent multiple clicks in Android Jetpack Compose.

3. 추가 리팩토링

SingleEventHandler를 사용하는 곳이 사용처마다 달라질 수도 있다고 생각이 들어 전략패턴을 사용하여 변경했습니다 ! c2de285

4. 테스트

솔직히 SingleEventHandler는 굳이 테스트 안해도 될 것 같습니다만.. 올만에 mockking해보고 싶어서 했습니다 :D

@murjune murjune self-assigned this Sep 15, 2023
@murjune murjune requested review from KWY0218 and 2zerozu September 15, 2023 12:46
@murjune murjune added 준원🐻 준원이가 작업함! feat 새로운 기능 추가 Pull Request🔥 풀리퀘 날림! labels Sep 15, 2023
Copy link
Member

@KWY0218 KWY0218 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

작업하시느라 고생하셨습니다!
저도 필요할 때 사용해야겠네요~!! 👍
코맨트 확인해주세요!

@murjune murjune requested a review from KWY0218 September 16, 2023 15:42
Copy link
Member

@KWY0218 KWY0218 left a 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@2zerozu 2zerozu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨숨다

Comment on lines +42 to +54
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"
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 이런식으로 쓰는군요 !!

Comment on lines +9 to +21
@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
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow

@murjune murjune merged commit 07f3766 into develop Sep 19, 2023
1 check passed
@murjune murjune deleted the feature/#277-compose-single-click branch March 10, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 새로운 기능 추가 Pull Request🔥 풀리퀘 날림! 준원🐻 준원이가 작업함!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat] Compose 버튼 SingleClick 되게 만들기
3 participants