fix: restore media viewer swipe navigation
Let the gallery pager keep single-finger horizontal swipes for images. Disable native PlayerView controls in the video viewer so video pages no longer steal paging gestures. Switch the ChatScreen file-level Media3 marker to the correct UnstableApi annotation.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
@file:OptIn(UnstableApi::class)
|
@file:UnstableApi
|
||||||
|
|
||||||
package ru.daemonlord.messenger.ui.chat
|
package ru.daemonlord.messenger.ui.chat
|
||||||
|
|
||||||
@@ -25,6 +25,8 @@ import androidx.compose.foundation.gestures.detectTransformGestures
|
|||||||
import androidx.compose.foundation.gestures.detectVerticalDragGestures
|
import androidx.compose.foundation.gestures.detectVerticalDragGestures
|
||||||
import androidx.compose.foundation.gestures.awaitEachGesture
|
import androidx.compose.foundation.gestures.awaitEachGesture
|
||||||
import androidx.compose.foundation.gestures.awaitFirstDown
|
import androidx.compose.foundation.gestures.awaitFirstDown
|
||||||
|
import androidx.compose.foundation.gestures.calculatePan
|
||||||
|
import androidx.compose.foundation.gestures.calculateZoom
|
||||||
import androidx.compose.foundation.gestures.waitForUpOrCancellation
|
import androidx.compose.foundation.gestures.waitForUpOrCancellation
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
@@ -2331,14 +2333,30 @@ private fun ZoomableImageViewerPage(
|
|||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.pointerInput(imageUrl) {
|
.pointerInput(imageUrl, scale) {
|
||||||
detectTransformGestures { _, pan, zoom, _ ->
|
awaitEachGesture {
|
||||||
val nextScale = (scale * zoom).coerceIn(1f, 4f)
|
awaitFirstDown(requireUnconsumed = false)
|
||||||
scale = nextScale
|
var gestureHandled = false
|
||||||
offset = if (nextScale <= 1.02f) {
|
do {
|
||||||
Offset.Zero
|
val event = awaitPointerEvent()
|
||||||
} else {
|
val pointerCount = event.changes.count { it.pressed }
|
||||||
offset + pan
|
val zoomChange = event.calculateZoom()
|
||||||
|
val panChange = event.calculatePan()
|
||||||
|
val shouldTransform = pointerCount > 1 || scale > 1.02f
|
||||||
|
if (shouldTransform && (zoomChange != 1f || panChange != Offset.Zero)) {
|
||||||
|
val nextScale = (scale * zoomChange).coerceIn(1f, 4f)
|
||||||
|
scale = nextScale
|
||||||
|
offset = if (nextScale <= 1.02f) {
|
||||||
|
Offset.Zero
|
||||||
|
} else {
|
||||||
|
offset + panChange
|
||||||
|
}
|
||||||
|
event.changes.forEach { if (it.pressed) it.consume() }
|
||||||
|
gestureHandled = true
|
||||||
|
}
|
||||||
|
} while (event.changes.any { it.pressed })
|
||||||
|
if (!gestureHandled && scale <= 1.02f) {
|
||||||
|
offset = Offset.Zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2439,10 +2457,8 @@ private fun VideoViewerPage(
|
|||||||
AndroidView(
|
AndroidView(
|
||||||
factory = { androidContext ->
|
factory = { androidContext ->
|
||||||
PlayerView(androidContext).apply {
|
PlayerView(androidContext).apply {
|
||||||
useController = true
|
useController = false
|
||||||
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
|
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
|
||||||
controllerAutoShow = true
|
|
||||||
controllerHideOnTouch = false
|
|
||||||
player = playerState.player
|
player = playerState.player
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user