Skip to content

Commit 452ce73

Browse files
authored
fix(mobile): more efficient loading local image on ios (immich-app#13426)
1 parent 346a084 commit 452ce73

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

mobile/lib/providers/image/immich_local_image_provider.dart

+8-34
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import 'package:cached_network_image/cached_network_image.dart';
77
import 'package:flutter/foundation.dart';
88
import 'package:flutter/painting.dart';
99
import 'package:immich_mobile/entities/asset.entity.dart';
10-
import 'package:immich_mobile/entities/store.entity.dart';
11-
import 'package:immich_mobile/services/app_settings.service.dart';
1210
import 'package:photo_manager/photo_manager.dart' show ThumbnailSize;
1311

1412
/// The local image provider for an asset
@@ -19,12 +17,6 @@ class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
1917
required this.asset,
2018
}) : assert(asset.local != null, 'Only usable when asset.local is set');
2119

22-
/// Whether to show the original file or load a compressed version
23-
bool get _useOriginal => Store.get(
24-
AppSettingsEnum.loadOriginal.storeKey,
25-
AppSettingsEnum.loadOriginal.defaultValue,
26-
);
27-
2820
/// Converts an [ImageProvider]'s settings plus an [ImageConfiguration] to a key
2921
/// that describes the precise image to load.
3022
@override
@@ -68,34 +60,16 @@ class ImmichLocalImageProvider extends ImageProvider<ImmichLocalImageProvider> {
6860
}
6961

7062
if (asset.isImage) {
71-
/// Using 2K thumbnail for local iOS image to avoid double swiping issue
72-
if (Platform.isIOS) {
73-
final largeImageBytes = _useOriginal
74-
? await asset.local?.originBytes
75-
: await asset.local
76-
?.thumbnailDataWithSize(const ThumbnailSize(3840, 2160));
77-
78-
if (largeImageBytes == null) {
79-
throw StateError(
80-
"Loading thumb for local photo ${asset.fileName} failed",
81-
);
82-
}
83-
final buffer = await ui.ImmutableBuffer.fromUint8List(largeImageBytes);
63+
final File? file = await asset.local?.originFile;
64+
if (file == null) {
65+
throw StateError("Opening file for asset ${asset.fileName} failed");
66+
}
67+
try {
68+
final buffer = await ui.ImmutableBuffer.fromFilePath(file.path);
8469
final codec = await decode(buffer);
8570
yield codec;
86-
} else {
87-
// Use the original file for Android
88-
final File? file = await asset.local?.originFile;
89-
if (file == null) {
90-
throw StateError("Opening file for asset ${asset.fileName} failed");
91-
}
92-
try {
93-
final buffer = await ui.ImmutableBuffer.fromFilePath(file.path);
94-
final codec = await decode(buffer);
95-
yield codec;
96-
} catch (error) {
97-
throw StateError("Loading asset ${asset.fileName} failed");
98-
}
71+
} catch (error) {
72+
throw StateError("Loading asset ${asset.fileName} failed");
9973
}
10074
}
10175

0 commit comments

Comments
 (0)