diff --git a/wearApp/src/main/java/com/surrus/peopleinspace/RotaryEventDispatcher.kt b/wearApp/src/main/java/com/surrus/peopleinspace/RotaryEventDispatcher.kt index b71cb6d..30fc35d 100644 --- a/wearApp/src/main/java/com/surrus/peopleinspace/RotaryEventDispatcher.kt +++ b/wearApp/src/main/java/com/surrus/peopleinspace/RotaryEventDispatcher.kt @@ -1,10 +1,10 @@ package com.surrus.peopleinspace -import android.content.Context import android.view.MotionEvent import android.view.ViewConfiguration import androidx.compose.foundation.gestures.ScrollableState import androidx.compose.foundation.gestures.scrollBy +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier @@ -14,34 +14,27 @@ import androidx.compose.ui.input.pointer.pointerInteropFilter import androidx.compose.ui.platform.LocalContext import androidx.core.view.InputDeviceCompat import androidx.core.view.MotionEventCompat -import androidx.core.view.ViewConfigurationCompat -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch -fun processEvent(context: Context, scope: CoroutineScope, event: MotionEvent, scrollState: ScrollableState): Boolean { - if (event.action != MotionEvent.ACTION_SCROLL || - !event.isFromSource(InputDeviceCompat.SOURCE_ROTARY_ENCODER) - ) { - return false - } - - val delta = -event.getAxisValue(MotionEventCompat.AXIS_SCROLL) * - ViewConfigurationCompat.getScaledVerticalScrollFactor( - ViewConfiguration.get(context), context - ) - scope.launch { - scrollState.scrollBy(delta) - } - return true -} - @OptIn(ExperimentalComposeUiApi::class) fun Modifier.scrollHandler(scrollState: ScrollableState): Modifier = composed { val context = LocalContext.current val scope = rememberCoroutineScope() + val scaledVerticalScrollFactor = + remember { ViewConfiguration.get(context).getScaledVerticalScrollFactor() } this.pointerInteropFilter(RequestDisallowInterceptTouchEvent()) { event -> - println(event) - processEvent(context, scope, event, scrollState) + if (event.action != MotionEvent.ACTION_SCROLL || + !event.isFromSource(InputDeviceCompat.SOURCE_ROTARY_ENCODER) + ) { + false + } else { + val delta = -event.getAxisValue(MotionEventCompat.AXIS_SCROLL) * + scaledVerticalScrollFactor + scope.launch { + scrollState.scrollBy(delta) + } + true + } } } \ No newline at end of file