Skip to content

Commit 37b70e0

Browse files
committed
fix live photo zoom
1 parent 1ba622a commit 37b70e0

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

mobile/lib/pages/common/gallery_viewer.page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class GalleryViewerPage extends HookConsumerWidget {
6161
final localPosition = useRef<Offset?>(null);
6262
final currentIndex = useValueNotifier(initialIndex);
6363
final loadAsset = renderList.loadAsset;
64+
final isPlayingMotionVideo = ref.watch(isPlayingMotionVideoProvider);
6465

6566
Future<void> precacheNextImage(int index) async {
6667
if (!context.mounted) {
@@ -249,7 +250,6 @@ class GalleryViewerPage extends HookConsumerWidget {
249250
}
250251

251252
PhotoViewGalleryPageOptions buildAsset(BuildContext context, int index) {
252-
ref.read(isPlayingMotionVideoProvider.notifier).playing = false;
253253
var newAsset = loadAsset(index);
254254
final stackId = newAsset.stackId;
255255
if (stackId != null && currentIndex.value == index) {
@@ -260,7 +260,7 @@ class GalleryViewerPage extends HookConsumerWidget {
260260
}
261261
}
262262

263-
if (newAsset.isImage && !newAsset.isMotionPhoto) {
263+
if (newAsset.isImage && !isPlayingMotionVideo) {
264264
return buildImage(context, newAsset);
265265
}
266266
return buildVideo(context, newAsset);
@@ -275,7 +275,7 @@ class GalleryViewerPage extends HookConsumerWidget {
275275
body: Stack(
276276
children: [
277277
PhotoViewGallery.builder(
278-
key: const ValueKey('gallery'),
278+
key: ValueKey(isPlayingMotionVideo),
279279
scaleStateChangedCallback: (state) {
280280
final asset = ref.read(currentAssetProvider);
281281
if (asset == null) {

mobile/lib/pages/common/native_video_viewer.page.dart

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
4040
final controller = useState<NativeVideoPlayerController?>(null);
4141
final lastVideoPosition = useRef(-1);
4242
final isBuffering = useRef(false);
43-
final showMotionVideo = useState(false);
4443

4544
// When a video is opened through the timeline, `isCurrent` will immediately be true.
4645
// When swiping from video A to video B, `isCurrent` will initially be true for video A and false for video B.
@@ -50,38 +49,18 @@ class NativeVideoViewerPage extends HookConsumerWidget {
5049
final isCurrent = currentAsset.value == asset;
5150

5251
// Used to show the placeholder during hero animations for remote videos to avoid a stutter
53-
final isVisible =
54-
useState((Platform.isIOS && asset.isLocal) || asset.isMotionPhoto);
52+
final isVisible = useState(Platform.isIOS && asset.isLocal);
5553

5654
final log = Logger('NativeVideoViewerPage');
5755

58-
ref.listen(isPlayingMotionVideoProvider, (_, value) async {
59-
final videoController = controller.value;
60-
if (!asset.isMotionPhoto || videoController == null || !context.mounted) {
61-
return;
62-
}
63-
64-
showMotionVideo.value = value;
65-
try {
66-
if (value) {
67-
await videoController.seekTo(0);
68-
await videoController.play();
69-
} else {
70-
await videoController.pause();
71-
}
72-
} catch (error) {
73-
log.severe('Error toggling motion video: $error');
74-
}
75-
});
76-
7756
Future<VideoSource?> createSource() async {
7857
if (!context.mounted) {
7958
return null;
8059
}
8160

8261
try {
8362
final local = asset.local;
84-
if (local != null && !asset.isMotionPhoto) {
63+
if (local != null) {
8564
final file = await local.file;
8665
if (file == null) {
8766
throw Exception('No file found for the video');
@@ -204,9 +183,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
204183
ref.read(videoPlaybackValueProvider.notifier).value = videoPlayback;
205184

206185
try {
207-
if (asset.isVideo || showMotionVideo.value) {
208-
await videoController.play();
209-
}
186+
await videoController.play();
210187
await videoController.setVolume(0.9);
211188
} catch (error) {
212189
log.severe('Error playing video: $error');
@@ -268,8 +245,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
268245
return;
269246
}
270247

271-
if (showMotionVideo.value &&
272-
videoController.playbackInfo?.status == PlaybackStatus.stopped &&
248+
if (videoController.playbackInfo?.status == PlaybackStatus.stopped &&
273249
!ref
274250
.read(appSettingsServiceProvider)
275251
.getSetting<bool>(AppSettingsEnum.loopVideo)) {
@@ -388,8 +364,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
388364
if (aspectRatio.value != null)
389365
Visibility.maintain(
390366
key: ValueKey(asset),
391-
visible:
392-
(asset.isVideo || showMotionVideo.value) && isVisible.value,
367+
visible: isVisible.value,
393368
child: Center(
394369
key: ValueKey(asset),
395370
child: AspectRatio(

mobile/lib/widgets/asset_grid/immich_asset_grid_view.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:immich_mobile/extensions/build_context_extensions.dart';
1313
import 'package:immich_mobile/extensions/collection_extensions.dart';
1414
import 'package:immich_mobile/extensions/theme_extensions.dart';
1515
import 'package:immich_mobile/providers/asset_viewer/current_asset.provider.dart';
16+
import 'package:immich_mobile/providers/asset_viewer/is_motion_video_playing.provider.dart';
1617
import 'package:immich_mobile/providers/asset_viewer/scroll_notifier.provider.dart';
1718
import 'package:immich_mobile/providers/asset_viewer/show_controls.provider.dart';
1819
import 'package:immich_mobile/widgets/asset_grid/asset_drag_region.dart';
@@ -206,6 +207,7 @@ class ImmichAssetGridViewState extends ConsumerState<ImmichAssetGridView> {
206207
heroOffset: widget.heroOffset,
207208
onAssetTap: (asset) {
208209
ref.read(currentAssetProvider.notifier).set(asset);
210+
ref.read(isPlayingMotionVideoProvider.notifier).playing = false;
209211
if (asset.isVideo) {
210212
ref.read(showControlsProvider.notifier).show = false;
211213
}

0 commit comments

Comments
 (0)