Skip to content

Commit

Permalink
Merge pull request #273 from School-of-Company/feature/272-create-mod…
Browse files Browse the repository at this point in the history
…ifier-custom-function

🔀 :: (#272) - create modifier custom function
  • Loading branch information
audgns10 authored Aug 19, 2024
2 parents 1f92cbb + 59c952d commit 2a0d4e3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
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
}
}
}
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() }
)
}
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
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.msg.certification.component.AddAcquisitionDateSection
import com.msg.certification.component.AddCertificationSection
import com.msg.certification.viewmodel.CertificationViewModel
import com.msg.design_system.component.button.BitgoeulButton
import com.msg.design_system.component.modifier.padding.paddingHorizontal
import com.msg.design_system.component.topbar.DetailSettingTopBar
import com.msg.design_system.theme.BitgoeulAndroidTheme
import com.msg.ui.DevicePreviews
Expand Down Expand Up @@ -82,11 +83,10 @@ internal fun AddCertificationScreen(
Column(
modifier = modifier
.fillMaxSize()
.padding(
.paddingHorizontal(
top = 24.dp,
bottom = 14.dp,
start = 28.dp,
end = 28.dp
horizontal = 28.dp
),
verticalArrangement = Arrangement.spacedBy(24.dp)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal fun LectureTakingStudentList(
data: List<Students>?,
onChangeCompleteState: (isComplete: Boolean, studentId: UUID) -> Unit,
) {
BitgoeulAndroidTheme { colors, typography ->
BitgoeulAndroidTheme { _, _ ->
LazyColumn(
modifier = modifier
.padding(vertical = 24.dp)
Expand Down

0 comments on commit 2a0d4e3

Please sign in to comment.