forked from boostcampwm-2022/android02-DailyFilm
-
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.
issue boostcampwm-2022#171 feat: rememberlifecyclerEvent , noRippleCl…
…ickable util 추가 Co-authored-by: junhyeongleeee <[email protected]>
- Loading branch information
1 parent
3a4dd10
commit 4483499
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/noRippleClickable.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 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() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/com/boostcamp/dailyfilm/presentation/util/compose/rememberLifecycleEvent.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,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 | ||
} |