Skip to content

Commit

Permalink
Fix link images not respecting edge-to-edge option (#1708)
Browse files Browse the repository at this point in the history
fix: link images not respecting edge-to-edge option
  • Loading branch information
hjiangsu authored Feb 20, 2025
1 parent d987e48 commit 162290c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/shared/image_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ImagePreview extends StatefulWidget {
final bool isGallery;
final bool isExpandable;
final bool showFullHeightImages;
final bool edgeToEdgeImages;
final int? postId;
final void Function()? navigateToPost;
final bool? isComment;
Expand All @@ -39,6 +40,7 @@ class ImagePreview extends StatefulWidget {
this.isGallery = false,
this.isExpandable = true,
this.showFullHeightImages = false,
this.edgeToEdgeImages = false,
this.postId,
this.navigateToPost,
this.isComment,
Expand Down Expand Up @@ -93,7 +95,7 @@ class _ImagePreviewState extends State<ImagePreview> {

return Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(widget.edgeToEdgeImages ? 0 : 12)),
child: Stack(
children: [
// This is used for link posts where the preview comes from Lemmy
Expand All @@ -108,7 +110,7 @@ class _ImagePreviewState extends State<ImagePreview> {
maxWidth: MediaQuery.of(context).size.width * 0.60,
)
: BoxConstraints(
maxWidth: widget.maxWidth ?? MediaQuery.of(context).size.width - 24,
maxWidth: widget.maxWidth ?? MediaQuery.of(context).size.width - (widget.edgeToEdgeImages ? 0 : 24),
),
alignment: widget.isComment == true ? Alignment.topCenter : Alignment.center,
widget.url!,
Expand Down
5 changes: 4 additions & 1 deletion lib/shared/link_information.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class LinkInformation extends StatefulWidget {
/// Type of media (image, link, text, etc.)
final MediaType? mediaType;

final bool showEdgeToEdgeImages;

/// Custom callback function for when the link is tapped
final Function? onTap;

Expand All @@ -30,6 +32,7 @@ class LinkInformation extends StatefulWidget {
required this.viewMode,
this.originURL,
this.mediaType,
this.showEdgeToEdgeImages = false,
this.onTap,
this.onLongPress,
});
Expand Down Expand Up @@ -75,7 +78,7 @@ class _LinkInformationState extends State<LinkInformation> {
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(widget.showEdgeToEdgeImages ? 0 : 12),
color: ElevationOverlay.applySurfaceTint(theme.colorScheme.surface.withValues(alpha: 0.8), theme.colorScheme.surfaceTint, 10),
),
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
Expand Down
3 changes: 3 additions & 0 deletions lib/shared/link_preview_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class LinkPreviewCard extends StatelessWidget {
url: mediaURL ?? originURL!,
height: showFullHeightImages ? mediaHeight : ViewMode.comfortable.height,
width: mediaWidth ?? MediaQuery.of(context).size.width - (edgeToEdgeImages ? 0 : 24),
edgeToEdgeImages: edgeToEdgeImages,
isExpandable: false,
),
)
Expand All @@ -86,6 +87,7 @@ class LinkPreviewCard extends StatelessWidget {
url: mediaURL ?? originURL!,
height: showFullHeightImages ? mediaHeight : ViewMode.comfortable.height,
width: mediaWidth ?? MediaQuery.of(context).size.width - (edgeToEdgeImages ? 0 : 24),
edgeToEdgeImages: edgeToEdgeImages,
isExpandable: false,
)
] else if (scrapeMissingPreviews)
Expand Down Expand Up @@ -129,6 +131,7 @@ class LinkPreviewCard extends StatelessWidget {
LinkInformation(
viewMode: viewMode,
originURL: originURL,
showEdgeToEdgeImages: edgeToEdgeImages,
),
Positioned.fill(
child: Material(
Expand Down
3 changes: 3 additions & 0 deletions lib/shared/media_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class _MediaViewState extends State<MediaView> with TickerProviderStateMixin {
viewMode: widget.viewMode,
mediaType: widget.postViewMedia.media.first.mediaType,
originURL: widget.postViewMedia.media.first.originalUrl ?? '',
showEdgeToEdgeImages: widget.edgeToEdgeImages,
),
),
),
Expand All @@ -371,6 +372,7 @@ class _MediaViewState extends State<MediaView> with TickerProviderStateMixin {
originURL: widget.postViewMedia.media.first.originalUrl,
mediaType: widget.postViewMedia.media.first.mediaType,
onTap: widget.postViewMedia.media.first.mediaType == MediaType.image ? showImage : null,
showEdgeToEdgeImages: widget.edgeToEdgeImages,
);
}
switch (widget.postViewMedia.media.firstOrNull?.mediaType) {
Expand All @@ -382,6 +384,7 @@ class _MediaViewState extends State<MediaView> with TickerProviderStateMixin {
viewMode: widget.viewMode,
mediaType: widget.postViewMedia.media.first.mediaType,
originURL: widget.postViewMedia.media.first.originalUrl ?? '',
showEdgeToEdgeImages: widget.edgeToEdgeImages,
);
}

Expand Down

0 comments on commit 162290c

Please sign in to comment.