Skip to content

Commit aa3ef57

Browse files
committed
content: Size images and video thumbnails according to realmMediaPreviewSize
Fixes #2177.
1 parent eb9e0e7 commit aa3ef57

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

lib/widgets/content.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,11 @@ class MessageMediaContainer extends StatelessWidget {
725725
final Widget? child;
726726

727727
/// The container's size, in logical pixels.
728-
static const size = Size(150, 100);
728+
static const baseSize = Size(150, 100);
729729

730730
@override
731731
Widget build(BuildContext context) {
732+
final store = PerAccountStoreWidget.of(context);
732733
return GestureDetector(
733734
onTap: onTap,
734735
child: UnconstrainedBox(
@@ -742,7 +743,7 @@ class MessageMediaContainer extends StatelessWidget {
742743
child: Padding(
743744
padding: const EdgeInsets.all(1),
744745
child: SizedBox.fromSize(
745-
size: size,
746+
size: baseSize * store.mediaPreviewSizeFactor,
746747
child: child))))));
747748
}
748749
}
@@ -1526,17 +1527,18 @@ class _Image extends StatelessWidget {
15261527

15271528
@override
15281529
Widget build(BuildContext context) {
1530+
final store = PerAccountStoreWidget.of(context);
15291531
final devicePixelRatio = MediaQuery.devicePixelRatioOf(context);
15301532

15311533
// Follow web's max-height behavior (10em);
15321534
// see image_box_em in web/src/postprocess_content.ts.
1533-
final maxHeight = ambientTextStyle.fontSize! * 10;
1535+
final maxHeight = ambientTextStyle.fontSize! * 10 * store.mediaPreviewSizeFactor;
15341536

15351537
final imageSize = (node.originalWidth != null && node.originalHeight != null)
15361538
? Size(node.originalWidth!, node.originalHeight!) / devicePixelRatio
15371539
// Layout plan when original dimensions are unknown:
15381540
// a [MessageMediaContainer]-sized and -colored rectangle.
1539-
: MessageMediaContainer.size;
1541+
: MessageMediaContainer.baseSize;
15401542

15411543
// (a) Don't let tall, thin images take up too much vertical space,
15421544
// which could be annoying to scroll through. And:
@@ -1549,7 +1551,6 @@ class _Image extends StatelessWidget {
15491551
final size = BoxConstraints(maxHeight: maxHeight)
15501552
.constrainSizeAndAttemptToPreserveAspectRatio(imageSize);
15511553

1552-
final store = PerAccountStoreWidget.of(context);
15531554
final message = InheritedMessage.of(context);
15541555

15551556
final resolvedSrc = switch (node.src) {

test/widgets/content_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,20 @@ void main() {
702702
check(images.map((i) => i.src).toList())
703703
.deepEquals(expectedImages.map((n) => otherSrc(n.src)));
704704
});
705+
706+
testWidgets('scale size by mediaPreviewSizeFactor', (tester) async {
707+
tester.view.devicePixelRatio = 1.0;
708+
addTearDown(tester.view.resetDevicePixelRatio);
709+
await prepareContent(tester,
710+
messageContent(ContentExample.imagePreviewSingle.html),
711+
initialSnapshot: eg.initialSnapshot(
712+
realmMediaPreviewSize: RealmMediaPreviewSize.large),
713+
wrapWithPerAccountStoreWidget: true);
714+
// The image is tall enough to use the max height: 10em,
715+
// with 1em = [kBaseFontSize]. Size gets doubled by the "large" setting.
716+
check(tester.getSize(find.byType(RealmContentNetworkImage)))
717+
.equals(Size(510, 340));
718+
});
705719
});
706720

707721
group("MessageInlineVideo", () {
@@ -734,6 +748,18 @@ void main() {
734748
check(pushedRoutes).single.isA<AccountPageRouteBuilder>()
735749
.fullscreenDialog.isTrue(); // opened lightbox
736750
});
751+
752+
testWidgets('scale thumbnail size by mediaPreviewSizeFactor', (tester) async {
753+
await prepareContent(tester,
754+
messageContent(ContentExample.videoInline.html),
755+
initialSnapshot: eg.initialSnapshot(
756+
realmMediaPreviewSize: RealmMediaPreviewSize.large),
757+
wrapWithPerAccountStoreWidget: true);
758+
check(tester.getSize(find.descendant(
759+
of: find.byType(MessageMediaContainer),
760+
matching: find.byType(Container)))
761+
).equals(MessageMediaContainer.baseSize * 2);
762+
});
737763
});
738764

739765
group("MessageEmbedVideo", () {

0 commit comments

Comments
 (0)