Skip to content

Commit

Permalink
Fix issue where having full height images enabled causes infinite loa…
Browse files Browse the repository at this point in the history
…ding screen (#1245)
  • Loading branch information
hjiangsu authored Mar 28, 2024
1 parent 3f8cc3b commit a1391f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/post/utils/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:thunder/core/models/media_extension.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:thunder/core/singletons/preferences.dart';
import 'package:thunder/utils/global_context.dart';
import 'package:thunder/utils/media/image.dart';
import 'package:thunder/utils/links.dart';
import 'package:thunder/utils/media/video.dart';
Expand Down Expand Up @@ -309,7 +310,14 @@ Future<PostViewMedia> parsePostView(PostView postView, bool fetchImageDimensions

// Finally, check to see if we need to fetch the image dimensions
if (fetchImageDimensions && media.mediaUrl != null) {
Size result = await retrieveImageDimensions(imageUrl: media.mediaUrl);
Size result = Size(MediaQuery.of(GlobalContext.context).size.width, 200);

try {
result = await retrieveImageDimensions(imageUrl: media.mediaUrl);
} catch (e) {
debugPrint('$e: Falling back to default image size');
}

Size size = MediaExtension.getScaledMediaSize(width: result.width, height: result.height, offset: edgeToEdgeImages ? 0 : 24, tabletMode: tabletMode);

media.width = size.width;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/media/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Future<Size> retrieveImageDimensions({String? imageUrl, Uint8List? imageBytes})
}
}
} catch (e) {
throw Exception('Failed to retrieve image dimensions');
throw Exception('Failed to retrieve image dimensions from $imageUrl: $e');
}

throw Exception('Invalid image type: $imageUrl');
Expand Down

0 comments on commit a1391f3

Please sign in to comment.