generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from School-of-Company/feature/272-create-mod…
…ifier-custom-function 🔀 :: (#272) - create modifier custom function
- Loading branch information
Showing
5 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...ain/java/com/msg/design_system/component/modifier/clickableSingle/MultipleEventsCutter.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 com.msg.design_system.component.modifier.clickableSingle | ||
|
||
internal interface MultipleEventsCutter { | ||
fun processEvent(event: () -> Unit) | ||
|
||
companion object | ||
} | ||
|
||
internal fun MultipleEventsCutter.Companion.get(): MultipleEventsCutter = MultipleEventsCutterImpl() | ||
|
||
private class MultipleEventsCutterImpl : MultipleEventsCutter { | ||
private var lastEventTimeMs: Long = 0 | ||
|
||
override fun processEvent(event: () -> Unit) { | ||
val now = System.currentTimeMillis() | ||
if (now - lastEventTimeMs >= 400L) { | ||
event.invoke() | ||
lastEventTimeMs = now | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...src/main/java/com/msg/design_system/component/modifier/clickableSingle/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,24 @@ | ||
package com.msg.design_system.component.modifier.clickableSingle | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
|
||
@SuppressLint("ModifierFactoryUnreferencedReceiver") | ||
@Stable | ||
fun Modifier.clickableSingle( | ||
enabled: Boolean = true, | ||
onClick: () -> Unit, | ||
) = composed { | ||
val multipleEventsCutter = remember { MultipleEventsCutter.get() } | ||
Modifier.clickable( | ||
enabled = enabled, | ||
onClick = { multipleEventsCutter.processEvent { onClick() } }, | ||
indication = null, | ||
interactionSource = remember { MutableInteractionSource() } | ||
) | ||
} |
19 changes: 19 additions & 0 deletions
19
core/design-system/src/main/java/com/msg/design_system/component/modifier/padding/padding.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,19 @@ | ||
package com.msg.design_system.component.modifier.padding | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Stable | ||
fun Modifier.paddingHorizontal( | ||
top: Dp = 0.dp, | ||
horizontal: Dp = 0.dp, | ||
bottom: Dp = 0.dp | ||
): Modifier = this then Modifier | ||
.padding(horizontal = horizontal) | ||
.padding( | ||
top = top, | ||
bottom = bottom | ||
) |
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