mirror of
https://github.com/jellyfin/jellyfin-androidtv.git
synced 2026-10-26 16:45:23 +00:00
Add new InteractionTracker API to compose to allow for user interaction detection
This commit is contained in:
1 parent
7600b4a27a
commit
74e24efcbf
1 file changed
+38
@@ -0,0 +1,38 @@
|
||||
package org.jellyfin.androidtv.ui.base
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
|
||||
typealias InteractionTracker = () -> Unit
|
||||
|
||||
private val DefaultInteractionTracker: InteractionTracker = {}
|
||||
|
||||
val LocalInteractionTracker = staticCompositionLocalOf<InteractionTracker> { DefaultInteractionTracker }
|
||||
|
||||
@Composable
|
||||
fun ProvideLocalInteractionTracker(
|
||||
interactionTracker: InteractionTracker,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
CompositionLocalProvider(
|
||||
LocalInteractionTracker provides interactionTracker
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier.interactionTracker(interactionTracker),
|
||||
) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Modifier.interactionTracker(
|
||||
interactionTracker: InteractionTracker = LocalInteractionTracker.current,
|
||||
): Modifier = onPreviewKeyEvent {
|
||||
interactionTracker()
|
||||
false
|
||||
}
|
||||
Reference in new issue
Block a user