-
Notifications
You must be signed in to change notification settings - Fork 0
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 #6 from lemoncloud-io/develop
Compose 유틸리티 모듈 추가
- Loading branch information
Showing
12 changed files
with
310 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,3 @@ | ||
# Compose-Util | ||
안드로이드 `Compose` 에서 사용되는 유틸리티 집합 | ||
여러 디바이스 및 환경을 대응하는 `Preview` 집합 및 `Modifier` 확장자 관련한 유틸리티 등이 존재합니다. |
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,12 @@ | ||
plugins { | ||
alias(libs.plugins.lemon.android.library) | ||
alias(libs.plugins.lemon.android.library.compose) | ||
alias(libs.plugins.lemon.android.compose.ext) | ||
alias(libs.plugins.lemon.android.feature) | ||
alias(libs.plugins.lemon.android.kotlin) | ||
} | ||
|
||
android { | ||
namespace = "io.lemon.core.compose.util" | ||
group = "io.lemon.core" | ||
} |
Empty file.
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 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
103 changes: 103 additions & 0 deletions
103
compose-util/src/main/java/io/lemon/core/compose/util/Modifier.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,103 @@ | ||
package io.lemon.core.compose.util | ||
|
||
import androidx.compose.foundation.Indication | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableLongStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
import androidx.compose.ui.semantics.Role | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* Click interaction 이 연속적으로 발생하는 것을 방지하는 확장자 | ||
*/ | ||
fun Modifier.throttleClickable( | ||
onClick: () -> Unit, | ||
enabled: Boolean = true, | ||
onClickLabel: String? = null, | ||
role: Role? = null, | ||
coroutineDispatcher: CoroutineDispatcher = Dispatchers.Main, | ||
throttleTime: Long = 250L, | ||
) = composed { | ||
val coroutineScope = rememberCoroutineScope { coroutineDispatcher } | ||
var lastEmissionTime: Long by remember { mutableLongStateOf(0L) } | ||
|
||
clickable( | ||
onClick = { | ||
val currentTime = System.currentTimeMillis() | ||
if (currentTime - lastEmissionTime >= throttleTime) { | ||
coroutineScope.launch { | ||
lastEmissionTime = currentTime | ||
onClick() | ||
} | ||
} | ||
lastEmissionTime = currentTime | ||
}, | ||
enabled = enabled, | ||
onClickLabel = onClickLabel, | ||
role = role, | ||
) | ||
} | ||
|
||
/** | ||
* Click interaction 이 연속적으로 발생하는 것을 방지하는 확장자 | ||
*/ | ||
fun Modifier.throttleClickable( | ||
onClick: () -> Unit, | ||
interactionSource: MutableInteractionSource = MutableInteractionSource(), | ||
indication: Indication? = null, | ||
enabled: Boolean = true, | ||
onClickLabel: String? = null, | ||
role: Role? = null, | ||
coroutineDispatcher: CoroutineDispatcher = Dispatchers.Main, | ||
throttleTime: Long = 250L, | ||
) = composed { | ||
val coroutineScope = rememberCoroutineScope { coroutineDispatcher } | ||
var lastEmissionTime: Long by remember { mutableLongStateOf(0L) } | ||
|
||
noRippleClickable( | ||
onClick = { | ||
val currentTime = System.currentTimeMillis() | ||
if (currentTime - lastEmissionTime >= throttleTime) { | ||
coroutineScope.launch { | ||
lastEmissionTime = currentTime | ||
onClick() | ||
} | ||
} | ||
lastEmissionTime = currentTime | ||
}, | ||
interactionSource = remember { interactionSource }, | ||
indication = indication, | ||
enabled = enabled, | ||
onClickLabel = onClickLabel, | ||
role = role | ||
) | ||
} | ||
|
||
/** | ||
* Click interaction 중 발생하는 시각 이펙트를 제거하는 확장자 | ||
*/ | ||
fun Modifier.noRippleClickable( | ||
onClick: () -> Unit, | ||
interactionSource: MutableInteractionSource = MutableInteractionSource(), | ||
indication: Indication? = null, | ||
enabled: Boolean = true, | ||
onClickLabel: String? = null, | ||
role: Role? = null, | ||
) = composed { | ||
clickable( | ||
interactionSource = remember { interactionSource }, | ||
indication = indication, | ||
enabled = enabled, | ||
onClickLabel = onClickLabel, | ||
onClick = onClick, | ||
role = role | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
compose-util/src/main/java/io/lemon/core/compose/util/preview/ComponentPreview.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,14 @@ | ||
package io.lemon.core.compose.util.preview | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
/** | ||
* A ComponentPreview annotation for displaying a @[Composable] method in a component. | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION) | ||
@Preview(name = "Night", group = "Component", uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Preview(name = "Day", group = "Component", uiMode = Configuration.UI_MODE_NIGHT_NO) | ||
annotation class ComponentPreview |
100 changes: 100 additions & 0 deletions
100
compose-util/src/main/java/io/lemon/core/compose/util/preview/DevicePreview.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,100 @@ | ||
package io.lemon.core.compose.util.preview | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Devices.FOLDABLE | ||
import androidx.compose.ui.tooling.preview.Devices.TABLET | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
/** | ||
* A PhoneDevicePreview annotation for displaying a @[Composable] method in a component using a phone device. | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target( | ||
AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION | ||
) | ||
@Preview( | ||
name = "Android Large Night", | ||
group = "Phone Device", | ||
device = "spec:width=412dp,height=846dp,dpi=480", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_YES | ||
) | ||
@Preview( | ||
name = "Android Large Day", | ||
group = "Phone Device", | ||
device = "spec:width=412dp,height=846dp,dpi=480", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_NO | ||
) | ||
@Preview( | ||
name = "Android Small Night", | ||
group = "Phone Device", | ||
device = "spec:width=360dp,height=640dp,dpi=480", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_YES | ||
) | ||
@Preview( | ||
name = "Android Small Day", | ||
group = "Phone Device", | ||
device = "spec:width=360dp,height=640dp,dpi=480", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_NO | ||
) | ||
annotation class PhoneDevicePreview | ||
|
||
/** | ||
* A FoldableDevicePreview annotation for displaying a @[Composable] method in a component using a foldable device. | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target( | ||
AnnotationTarget.ANNOTATION_CLASS, | ||
AnnotationTarget.FUNCTION | ||
) | ||
@Preview( | ||
name = "Foldable Night", | ||
group = "Foldable Device", | ||
device = FOLDABLE, | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_YES, | ||
) | ||
@Preview( | ||
name = "Foldable Day", | ||
group = "Foldable Device", | ||
device = FOLDABLE, | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_NO | ||
) | ||
annotation class FoldableDevicePreview | ||
|
||
/** | ||
* A TabletDevicePreview annotation for displaying a @[Composable] method in a component using a tablet device. | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target( | ||
AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION | ||
) | ||
@Preview( | ||
name = "Tablet Night", | ||
group = "Tablet Device", | ||
device = "spec:width=1280dp,height=800dp,dpi=240", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_YES | ||
) | ||
@Preview( | ||
name = "Tablet Day", | ||
group = "Tablet Device", | ||
device = TABLET, | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_NO | ||
) | ||
annotation class TabletDevicePreview | ||
|
||
/** | ||
* A MultiDevicePreview annotation for displaying a @[Composable] method in a component using the screen sizes of three different reference devices. | ||
*/ | ||
|
||
@PhoneDevicePreview | ||
@FoldableDevicePreview | ||
@TabletDevicePreview | ||
annotation class MultiDevicePreview |
42 changes: 42 additions & 0 deletions
42
compose-util/src/main/java/io/lemon/core/compose/util/preview/LandscapeDevicePreview.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,42 @@ | ||
package io.lemon.core.compose.util.preview | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
/** | ||
* A LandscapeDevicePreview annotation for displaying a @[Composable] method in a component using a phone device in landscape mode. | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target( | ||
AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION | ||
) | ||
@Preview( | ||
name = "Landscape Android Large Night", | ||
group = "Landscape Phone Device", | ||
device = "spec:width=412dp,height=846dp,dpi=480,orientation=landscape", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_YES | ||
) | ||
@Preview( | ||
name = "Landscape Android Large Day", | ||
group = "Landscape Phone Device", | ||
device = "spec:width=412dp,height=846dp,dpi=480,orientation=landscape", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_NO | ||
) | ||
@Preview( | ||
name = "Landscape Android Small Night", | ||
group = "Landscape Phone Device", | ||
device = "spec:width=360dp,height=640dp,dpi=480,orientation=landscape", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_YES | ||
) | ||
@Preview( | ||
name = "Landscape Android Small Day", | ||
group = "Landscape Phone Device", | ||
device = "spec:width=360dp,height=640dp,dpi=480,orientation=landscape", | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_NO | ||
) | ||
annotation class LandscapeDevicePreview |
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