fix(player): harden pinch zoom activation

This commit is contained in:
edde746
2026-06-14 11:08:14 +02:00
parent edd0618e64
commit e7809b3160
2 changed files with 21 additions and 5 deletions
+20 -5
View File
@@ -2,7 +2,8 @@ part of '../../video_player_screen.dart';
extension _VideoPlayerBuildMethods on VideoPlayerScreenState { extension _VideoPlayerBuildMethods on VideoPlayerScreenState {
static const double _videoLayoutSizeTolerance = 0.1; static const double _videoLayoutSizeTolerance = 0.1;
static const double _pinchZoomActivationThreshold = 0.015; static const double _pinchZoomActivationThreshold = 0.06;
static const int _pinchZoomActivationUpdateThreshold = 3;
bool _isSameVideoLayoutSize(Size a, Size b) { bool _isSameVideoLayoutSize(Size a, Size b) {
return (a.width - b.width).abs() <= _videoLayoutSizeTolerance && return (a.width - b.width).abs() <= _videoLayoutSizeTolerance &&
@@ -143,14 +144,15 @@ extension _VideoPlayerBuildMethods on VideoPlayerScreenState {
final filterManager = _videoFilterManager; final filterManager = _videoFilterManager;
if (filterManager == null || _isPinchZooming) return; if (filterManager == null || _isPinchZooming) return;
_ambientLightingService?.disable();
_isPinchZooming = true; _isPinchZooming = true;
_pinchZoomActivationUpdateCount = 0;
_pinchZoomChanged = false; _pinchZoomChanged = false;
_pinchStartZoomScale = filterManager.zoomScale; _pinchStartZoomScale = filterManager.zoomScale;
} }
void _clearMobileZoomGesture() { void _clearMobileZoomGesture() {
_isPinchZooming = false; _isPinchZooming = false;
_pinchZoomActivationUpdateCount = 0;
_pinchZoomChanged = false; _pinchZoomChanged = false;
_pinchStartZoomScale = null; _pinchStartZoomScale = null;
} }
@@ -179,10 +181,23 @@ extension _VideoPlayerBuildMethods on VideoPlayerScreenState {
final startZoom = _pinchStartZoomScale; final startZoom = _pinchStartZoomScale;
final filterManager = _videoFilterManager; final filterManager = _videoFilterManager;
if (!_isPinchZooming || startZoom == null || filterManager == null) return; if (!_isPinchZooming || startZoom == null || filterManager == null) return;
if ((details.scale - 1.0).abs() <= _pinchZoomActivationThreshold && !_pinchZoomChanged) return; final nextZoomScale = VideoFilterManager.normalizeZoomScale(startZoom * details.scale);
_pinchZoomChanged = true; if (!_pinchZoomChanged) {
filterManager.setZoomScale(startZoom * details.scale); if ((details.scale - 1.0).abs() <= _pinchZoomActivationThreshold) {
_pinchZoomActivationUpdateCount = 0;
return;
}
_pinchZoomActivationUpdateCount++;
if (_pinchZoomActivationUpdateCount < _pinchZoomActivationUpdateThreshold) return;
if (nextZoomScale == filterManager.zoomScale) return;
_pinchZoomChanged = true;
_ambientLightingService?.disable();
}
filterManager.setZoomScale(nextZoomScale);
}, },
onScaleEnd: (details) { onScaleEnd: (details) {
if (!isMobile) return; if (!isMobile) return;
+1
View File
@@ -411,6 +411,7 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
Player? _lastVideoLayoutPlayer; Player? _lastVideoLayoutPlayer;
bool _videoLayoutUpdateScheduled = false; bool _videoLayoutUpdateScheduled = false;
double? _pinchStartZoomScale; double? _pinchStartZoomScale;
int _pinchZoomActivationUpdateCount = 0;
bool _isPinchZooming = false; bool _isPinchZooming = false;
bool _pinchZoomChanged = false; bool _pinchZoomChanged = false;
final EpisodeNavigationService _episodeNavigation = EpisodeNavigationService(); final EpisodeNavigationService _episodeNavigation = EpisodeNavigationService();