From 448349945d5d8b3028f27c74d670b50afefce041 Mon Sep 17 00:00:00 2001 From: junhyeongleeee Date: Tue, 25 Jul 2023 21:13:20 +0900 Subject: [PATCH] =?UTF-8?q?issue=20#171=20feat:=20rememberlifecyclerEvent?= =?UTF-8?q?=20,=20noRippleClickable=20util=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: junhyeongleeee --- .../util/compose/noRippleClickable.kt | 14 ++++++++++ .../util/compose/rememberLifecycleEvent.kt | 27 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/noRippleClickable.kt create mode 100644 app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/rememberLifecycleEvent.kt diff --git a/app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/noRippleClickable.kt b/app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/noRippleClickable.kt new file mode 100644 index 0000000..d2d4793 --- /dev/null +++ b/app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/noRippleClickable.kt @@ -0,0 +1,14 @@ +package com.boostcamp.dailyfilm.presentation.util.compose + +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 + +inline fun Modifier.noRippleClickable(crossinline onClick: ()->Unit): Modifier = composed { + clickable(indication = null, + interactionSource = remember { MutableInteractionSource() }) { + onClick() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/rememberLifecycleEvent.kt b/app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/rememberLifecycleEvent.kt new file mode 100644 index 0000000..df2822c --- /dev/null +++ b/app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/rememberLifecycleEvent.kt @@ -0,0 +1,27 @@ +package com.boostcamp.dailyfilm.presentation.util.compose + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver +import androidx.lifecycle.LifecycleOwner + +@Composable +fun rememberLifecycleEvent(lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current): Lifecycle.Event { + var state by remember { mutableStateOf(Lifecycle.Event.ON_ANY) } + DisposableEffect(lifecycleOwner) { + val observer = LifecycleEventObserver { _, event -> + state = event + } + lifecycleOwner.lifecycle.addObserver(observer) + onDispose { + lifecycleOwner.lifecycle.removeObserver(observer) + } + } + return state +} \ No newline at end of file