Skip to content

Instantly share code, notes, and snippets.

View AlShevelev's full-sized avatar

Alexander Shevelev AlShevelev

View GitHub Profile
@Composable
internal fun CoordinatedScroll(
collapsingAreaHeightPx: MutableState<Float> = remember { mutableStateOf(0f) },
content: @Composable (Float, NestedScrollConnection) -> Unit
) {
val toolbarOffsetHeightPx = remember { mutableStateOf(0f) }
val currentAbsoluteOffsetPx = remember { mutableStateOf(0f) }
val nestedScrollConnection = remember {
object : NestedScrollConnection {
fun Modifier.clickableSingle(
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onClick: () -> Unit
) = composed(
inspectorInfo = debugInspectorInfo {
name = "clickable"
properties["enabled"] = enabled
properties["onClickLabel"] = onClickLabel
internal interface MultipleEventsCutter {
fun processEvent(event: () -> Unit)
companion object
}
internal fun MultipleEventsCutter.Companion.get(): MultipleEventsCutter =
MultipleEventsCutterImpl()
private class MultipleEventsCutterImpl : MultipleEventsCutter {
multipleEventsCutter { manager ->
Card(
onClick = { manager.processEvent {...} }
) {
...
}
}
Row(
modifier = modifier.clickableSingle(onClick = { ... }),
) {
...
}
fun Modifier.clickableSingle(
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onClick: () -> Unit
) = composed(
inspectorInfo = debugInspectorInfo {
name = "clickable"
properties["enabled"] = enabled
properties["onClickLabel"] = onClickLabel
interface MultipleEventsCutterManager {
fun processEvent(event: () -> Unit)
}
@OptIn(FlowPreview::class)
@Composable
fun <T>multipleEventsCutter(
content: @Composable (MultipleEventsCutterManager) -> T
) : T {
val debounceState = remember {
private var a: Int by LazyMutable { getAValue() }
private fun getAValue(): Int {
return 5
}
class LazyMutable<T>(val initializer: () -> T) {
private object UninitializedValue
@Volatile private var propValue: Any? = UninitializedValue
@Suppress("UNCHECKED_CAST")
operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
val localValue = propValue
if(localValue != UninitializedValue) {
return localValue as T
private var a: Int by lazy { getAValue() }
private fun getAValue(): Int {
return 5
}