diff --git a/mobile/lib/presentation/widgets/asset_viewer/asset_page.widget.dart b/mobile/lib/presentation/widgets/asset_viewer/asset_page.widget.dart index 43b31b829cd05..6815ec8a1e01f 100644 --- a/mobile/lib/presentation/widgets/asset_viewer/asset_page.widget.dart +++ b/mobile/lib/presentation/widgets/asset_viewer/asset_page.widget.dart @@ -343,7 +343,7 @@ class _AssetPageState extends ConsumerState { } return PhotoView.customChild( - key: ValueKey(displayAsset), + key: ValueKey((displayAsset.heroTag, '_video_gesture_layer')), onDragStart: _onDragStart, onDragUpdate: _onDragUpdate, onDragEnd: _onDragEnd, @@ -359,7 +359,7 @@ class _AssetPageState extends ConsumerState { enablePanAlways: true, backgroundDecoration: backgroundDecoration, child: NativeVideoViewer( - key: ValueKey(displayAsset), + key: ValueKey((displayAsset.heroTag, '_video_platform_view')), asset: displayAsset, scaleStateNotifier: _videoScaleStateNotifier, disableScaleGestures: showingDetails, diff --git a/mobile/lib/presentation/widgets/asset_viewer/video_viewer.widget.dart b/mobile/lib/presentation/widgets/asset_viewer/video_viewer.widget.dart index 0f6568e8fd4c3..c41bf55e26f25 100644 --- a/mobile/lib/presentation/widgets/asset_viewer/video_viewer.widget.dart +++ b/mobile/lib/presentation/widgets/asset_viewer/video_viewer.widget.dart @@ -335,13 +335,21 @@ class NativeVideoViewer extends HookConsumerWidget { } ref.listen(currentAssetNotifier, (_, value) { + final isCurrent = _isCurrentAsset(asset, value); + // This is the same asset with different metadata (e.g. isFavorite changed), update the ref + if (value != null && value != asset && isCurrent) { + currentAsset.value = value; + isVisible.value = isCurrent; + return; + } + final playerController = controller.value; if (playerController != null && value != asset) { removeListeners(playerController); } if (value != null) { - isVisible.value = _isCurrentAsset(value, asset); + isVisible.value = isCurrent; } final curAsset = currentAsset.value; if (curAsset == asset) { @@ -423,17 +431,20 @@ class NativeVideoViewer extends HookConsumerWidget { if (!isVisible.value || controller.value == null) Center(key: ValueKey(asset.heroTag), child: image), if (aspectRatio.value != null && !isCasting && isCurrent) Visibility.maintain( - key: ValueKey(asset), + key: ValueKey((asset.heroTag, '_video_layer')), visible: isVisible.value, child: PhotoView.customChild( - key: ValueKey(asset), + key: ValueKey((asset.heroTag, '_video_gesture_layer')), enableRotation: false, disableScaleGestures: disableScaleGestures, // Transparent to avoid a black flash when viewer becomes visible but video isn't loaded yet. backgroundDecoration: const BoxDecoration(color: Colors.transparent), scaleStateChangedCallback: (state) => scaleStateNotifier?.value = state, childSize: videoContextSize(aspectRatio.value, context), - child: NativeVideoPlayerView(key: ValueKey(asset), onViewReady: initController), + child: NativeVideoPlayerView( + key: ValueKey((asset.heroTag, '_video_platform_view')), + onViewReady: initController, + ), ), ), if (showControls) const Center(child: VideoViewerControls()),