Stefan Oltmann
03/14/2022, 12:37 PM.pointerInput(Unit) {}
can only take one argument?
I have one call to detectTransformGestures
, but if I add another thing like
detectTapGestures(
onPress = {
println("ON PRESS")
}
)
or detectDragGestures
before that it's never called.
Only the first of these are called and all others are ignored.
I don't know how I'm supposed to combine a drag handler with a pinch-zoom detection...
The "pan" does not help me, because I don't know when the drag is ended (the finger lifted).Albert Chang
03/14/2022, 12:47 PMdetect*Gestures
are suspend functions that will never end. You can just use multiple pointer input modifiers.Stefan Oltmann
03/14/2022, 1:10 PMdetectTransformGestures
does not go well together with detectDragGestures
because now most of my input is recognized as pan
, only a bit as drag.
I only wanted a way to detect pinch-to-zoom on Android without the pan, but this does not seem to exist. 🤔Albert Chang
03/14/2022, 1:22 PMdetect*Gestures
function. See this.Stefan Oltmann
03/14/2022, 1:22 PMAlbert Chang
03/14/2022, 2:58 PMStefan Oltmann
03/14/2022, 3:01 PMAlbert Chang
03/15/2022, 12:53 AMStefan Oltmann
03/15/2022, 9:09 AMModifier.aspectRatio(size.width / size.height).fillMaxSize()
is important to ensure it works correctly (for me).
Very nice work! ❤️
On Android at least I got now what I wanted. ✅FloatRange
annotations, which are not available to compose-jb. I replaced fastAny
and fastForEach
with the normal versions - but I learned that including implementation(compose("org.jetbrains.compose.ui:ui-util"))
would make that available also.
I did not need to make any changes to your code for scrollwheel support thanks to the exposed state:
val scope = rememberCoroutineScope()
val zoomableState = rememberZoomableState()
Zoomable(
state = zoomableState,
onTap = {
if (!photoState.photoEditMode)
store.dispatch(PhotoAction.ToggleFullScreen)
},
modifier = Modifier
.weight(1.0f)
.onMouseScrollEvent { distance ->
scope.launch {
zoomableState.animateScaleTo(
zoomableState.scale - distance
)
}
}
) {
// my Image composable
}
common:
expect fun Modifier.onMouseScrollEvent(
onScroll: (Float) -> Unit
): Modifier
desktop:
@OptIn(ExperimentalComposeUiApi::class)
@Suppress("kotlin:S1172")
actual fun Modifier.onMouseScrollEvent(
onScroll: (Float) -> Unit
): Modifier = Modifier.onPointerEvent(PointerEventType.Scroll) {
onScroll(this.currentEvent.changes.first().scrollDelta.y)
}
android:
@Suppress("kotlin:S1172")
actual fun Modifier.onMouseScrollEvent(
onScroll: (Float) -> Unit
): Modifier = this
So my question is: How important is the FloatRange
annotation here and could it be replaced with something else?
If you could get rid of it the library would be fully compatible with compose-jb and be usable on desktop. Click, double-click and panning are working out of the box.Albert Chang
03/15/2022, 2:14 PMStefan Oltmann
03/15/2022, 2:18 PMonMouseScrollEvent()
from the outside).
I had to copy the code (to removed FloatRange usage).
But I see a way where you could make it with little effort work for Android and compose-jb. And actually I would prefer to use it as a dependency from maven instead of copying those two classes.
Just wanted that you know that you could extend the use of your library.Albert Chang
03/15/2022, 2:38 PMStefan Oltmann
03/15/2022, 2:39 PMAlbert Chang
03/15/2022, 2:45 PMStefan Oltmann
03/15/2022, 2:50 PMAlbert Chang
03/19/2022, 4:05 PM1.5.0-mp-SNAPSHOT
) of the multiplatform version. Could you please try it and check if it works in both desktop and android modules?
You can find how to use snapshot builds in the README.Stefan Oltmann
03/21/2022, 8:27 AM