-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e93519f
#277 [chore] DimensionExt 이름 변경 및 패키징
murjune 1e5d844
#277 [feat] SingleEventHandler
murjune b95b161
#277 [ui] singleClickable Modifier
murjune d7b1aed
#277 [ui] SingleEventArea composable
murjune 8337ceb
#277 [fix] HousFloatingButton에 SingleEventArea 적용
murjune 0406da8
#277 [fix] RulePhotoStatusBar에 SingleEventArea 적용
murjune 169b1af
#277 [chore] ktlint
murjune c2de285
#277 [refactor] SingleEventHandler로 네이밍 변경 및 로직 변경
murjune 5e6e1c0
#277 [refactor] SingleEventHandler 적용
murjune fffc2d6
#277 [fix] KWY 코드 리뷰 반영
murjune 3748704
#277 [build(designsystem)] test 의존성 추가, jvm 버전 11업
murjune e922ce3
#277 [test] ThrottledDuration전략 test
murjune 33a6630
#277 [test] SingleEventHandelr test
murjune File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import androidx.compose.ui.res.vectorResource | |
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import hous.release.designsystem.R | ||
import hous.release.designsystem.component.user_interaction.SingleEventArea | ||
import hous.release.designsystem.theme.HousBlue | ||
import hous.release.designsystem.theme.HousWhite | ||
|
||
|
@@ -38,28 +39,31 @@ fun FabScreenSlot( | |
fun HousFloatingButton( | ||
onClick: () -> Unit = {} | ||
) { | ||
FloatingActionButton( | ||
onClick = onClick, | ||
backgroundColor = HousBlue, | ||
contentColor = HousWhite, | ||
modifier = Modifier.size(92.dp).padding(16.dp) | ||
) { | ||
Icon( | ||
imageVector = ImageVector.vectorResource(id = R.drawable.ic_plus), | ||
contentDescription = "Add" | ||
) | ||
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" | ||
) | ||
} | ||
Comment on lines
+42
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 이런식으로 쓰는군요 !! |
||
} | ||
} | ||
|
||
@Composable | ||
@Preview(showBackground = true) | ||
fun Preview() { | ||
private fun Preview() { | ||
HousFloatingButton() | ||
} | ||
|
||
@Composable | ||
@Preview(widthDp = 360, heightDp = 640, showBackground = true) | ||
fun PreviewFabContainerWithContent() { | ||
private fun PreviewFabContainerWithContent() { | ||
FabScreenSlot( | ||
fabOnClick = {}, | ||
content = { | ||
|
17 changes: 17 additions & 0 deletions
17
...tem/src/main/java/hous/release/designsystem/component/user_interaction/SingleEventArea.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package hous.release.designsystem.component.user_interaction | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import hous.release.designsystem.util.single_event.SingleEventHandler | ||
|
||
/** | ||
* 여러 번 클릭 이벤트를 막아주는 Wrapper Composable | ||
* */ | ||
@Composable | ||
fun <T> SingleEventArea( | ||
content: @Composable (SingleEventHandler) -> T | ||
) { | ||
val singleEventHandler = remember { SingleEventHandler() } | ||
|
||
content(singleEventHandler) | ||
} |
39 changes: 39 additions & 0 deletions
39
designsystem/src/main/java/hous/release/designsystem/modifier/ClickableSingle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package hous.release.designsystem.modifier | ||
|
||
import androidx.compose.foundation.LocalIndication | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
import androidx.compose.ui.platform.debugInspectorInfo | ||
import androidx.compose.ui.semantics.Role | ||
import hous.release.designsystem.util.single_event.SingleEventHandler | ||
|
||
/** | ||
* 여러 번 클릭 이벤트를 막아주는 Modifier | ||
* */ | ||
fun Modifier.clickableSingle( | ||
enabled: Boolean = true, | ||
onClickLabel: String? = null, | ||
role: Role? = null, | ||
onClick: () -> Unit | ||
): Modifier = composed( | ||
inspectorInfo = debugInspectorInfo { | ||
name = "clickable" | ||
properties["enabled"] = enabled | ||
properties["onClickLabel"] = onClickLabel | ||
properties["role"] = role | ||
properties["onClick"] = onClick | ||
} | ||
) { | ||
val manager = remember { SingleEventHandler() } | ||
Modifier.clickable( | ||
enabled = enabled, | ||
onClickLabel = onClickLabel, | ||
onClick = { manager.handle { onClick() } }, | ||
role = role, | ||
indication = LocalIndication.current, | ||
interactionSource = remember { MutableInteractionSource() } | ||
) | ||
} |
2 changes: 1 addition & 1 deletion
2
...lease/designsystem/util/DimensionUtils.kt → ...signsystem/util/extension/DimensionExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...em/src/main/java/hous/release/designsystem/util/single_event/SingleEventHandleStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package hous.release.designsystem.util.single_event | ||
|
||
fun interface SingleEventHandleStrategy { | ||
fun handle(event: () -> Unit) | ||
} |
9 changes: 9 additions & 0 deletions
9
designsystem/src/main/java/hous/release/designsystem/util/single_event/SingleEventHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package hous.release.designsystem.util.single_event | ||
|
||
class SingleEventHandler( | ||
private val singleEventHandleStrategy: SingleEventHandleStrategy = ThrottledDurationStrategy() | ||
) { | ||
fun handle(event: () -> Unit) { | ||
singleEventHandleStrategy.handle(event) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...em/src/main/java/hous/release/designsystem/util/single_event/ThrottledDurationStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package hous.release.designsystem.util.single_event | ||
|
||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.milliseconds | ||
import kotlin.time.ExperimentalTime | ||
import kotlin.time.TimeMark | ||
import kotlin.time.TimeSource | ||
|
||
@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 | ||
} | ||
} | ||
Comment on lines
+9
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow |
29 changes: 29 additions & 0 deletions
29
...ystem/src/test/java/hous/release/designsystem/util/single_event/SingleEventHandlerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package hous.release.designsystem.util.single_event | ||
|
||
import hous.release.testing.CoroutinesTestExtension | ||
import io.mockk.every | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@ExtendWith(CoroutinesTestExtension::class) | ||
@ExtendWith(MockKExtension::class) | ||
internal class SingleEventHandlerTest { | ||
|
||
@Test | ||
fun `이벤트를 처리할 때 내부적으로 SingleEventHandleStrategy의 handle을 호출 한다`() { | ||
// given | ||
val mockStrategy = mockk<SingleEventHandleStrategy>(relaxed = true) | ||
val handler = SingleEventHandler(mockStrategy) | ||
|
||
// when | ||
every { mockStrategy.handle(any()) } returns Unit | ||
handler.handle { } | ||
// then | ||
verify(exactly = 1) { handler.handle(any()) } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...rc/test/java/hous/release/designsystem/util/single_event/ThrottledDurationStrategyTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package hous.release.designsystem.util.single_event | ||
|
||
import com.google.common.truth.Truth | ||
import hous.release.testing.CoroutinesTestExtension | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@ExtendWith(CoroutinesTestExtension::class) | ||
internal class ThrottledDurationStrategyTest { | ||
|
||
@Test | ||
fun `마지막 이벤트가 발생한 지 300ms가 지나지 않고 추가 이벤트가 발생시 무시한다`() = runTest { | ||
// given | ||
val strategy = ThrottledDurationStrategy() | ||
var count = 0 | ||
// when | ||
strategy.handle { | ||
count++ | ||
} | ||
delay(301) | ||
strategy.handle { | ||
count++ | ||
} | ||
// then | ||
Truth.assertThat(count).isEqualTo(1) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍