Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 90 additions & 87 deletions lib/shared/comment_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,99 +89,102 @@ class _CommentContentState extends State<CommentContent> with SingleTickerProvid

return ExcludeSemantics(
excluding: widget.excludeSemantics,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
CommentHeader(
moddingCommentId: widget.moddingCommentId ?? -1,
comment: widget.comment,
now: widget.now,
isOwnComment: widget.isOwnComment,
isHidden: widget.isHidden,
moderators: widget.moderators ?? [],
),
AnimatedSwitcher(
duration: const Duration(milliseconds: 130),
switchInCurve: Curves.easeInOut,
switchOutCurve: Curves.easeInOut,
transitionBuilder: (Widget child, Animation<double> animation) {
return SizeTransition(
sizeFactor: animation,
child: SlideTransition(
position: _offsetAnimation,
child: child,
),
);
},
child: (widget.isHidden && collapseParentCommentOnGesture)
? Container()
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(top: 0, right: 8.0, left: 8.0, bottom: (state.showCommentButtonActions && widget.isUserLoggedIn && !widget.disableActions) ? 0.0 : 8.0),
child: ConditionalParentWidget(
condition: widget.selectable,
parentBuilder: (child) {
return SelectableRegion(
focusNode: _selectableRegionFocusNode,
// See comments on [SelectableTextModal] regarding the next two properties
selectionControls: Platform.isIOS ? cupertinoTextSelectionHandleControls : materialTextSelectionHandleControls,
contextMenuBuilder: (context, selectableRegionState) {
return AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: selectableRegionState.contextMenuButtonItems,
anchors: selectableRegionState.contextMenuAnchors,
);
},
child: child,
);
},
child: widget.viewSource
? ScalableText(
cleanCommentContent(widget.comment.comment),
style: theme.textTheme.bodySmall?.copyWith(fontFamily: 'monospace'),
fontScale: state.contentFontSizeScale,
)
: CommonMarkdownBody(
body: cleanCommentContent(widget.comment.comment),
isComment: true,
),
),
),
if (state.showCommentButtonActions && widget.isUserLoggedIn && !widget.disableActions)
child: AnimatedSize(
duration: const Duration(milliseconds: 250),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
CommentHeader(
moddingCommentId: widget.moddingCommentId ?? -1,
comment: widget.comment,
now: widget.now,
isOwnComment: widget.isOwnComment,
isHidden: widget.isHidden,
moderators: widget.moderators ?? [],
),
AnimatedSwitcher(
duration: const Duration(milliseconds: 130),
switchInCurve: Curves.easeInOut,
switchOutCurve: Curves.easeInOut,
transitionBuilder: (Widget child, Animation<double> animation) {
return SizeTransition(
sizeFactor: animation,
child: SlideTransition(
position: _offsetAnimation,
child: child,
),
);
},
child: (widget.isHidden && collapseParentCommentOnGesture)
? Container()
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 4, top: 6, right: 4.0),
child: CommentCardActions(
commentView: widget.comment,
onVoteAction: (int commentId, int vote) => widget.onVoteAction(commentId, vote),
isEdit: widget.isOwnComment,
onSaveAction: widget.onSaveAction,
onDeleteAction: widget.onDeleteAction,
onReplyEditAction: widget.onReplyEditAction,
onReportAction: widget.onReportAction,
onViewSourceToggled: widget.onViewSourceToggled,
viewSource: widget.viewSource,
padding: EdgeInsets.only(top: 0, right: 8.0, left: 8.0, bottom: (state.showCommentButtonActions && widget.isUserLoggedIn && !widget.disableActions) ? 0.0 : 8.0),
child: ConditionalParentWidget(
condition: widget.selectable,
parentBuilder: (child) {
return SelectableRegion(
focusNode: _selectableRegionFocusNode,
// See comments on [SelectableTextModal] regarding the next two properties
selectionControls: Platform.isIOS ? cupertinoTextSelectionHandleControls : materialTextSelectionHandleControls,
contextMenuBuilder: (context, selectableRegionState) {
return AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: selectableRegionState.contextMenuButtonItems,
anchors: selectableRegionState.contextMenuAnchors,
);
},
child: child,
);
},
child: widget.viewSource
? ScalableText(
cleanCommentContent(widget.comment.comment),
style: theme.textTheme.bodySmall?.copyWith(fontFamily: 'monospace'),
fontScale: state.contentFontSizeScale,
)
: CommonMarkdownBody(
body: cleanCommentContent(widget.comment.comment),
isComment: true,
),
),
),
],
),
),
if (widget.showReplyEditorButtons && widget.comment.comment.content.isNotEmpty == true) ...[
const Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: ThunderDivider(sliver: false, padding: false),
if (state.showCommentButtonActions && widget.isUserLoggedIn && !widget.disableActions)
Padding(
padding: const EdgeInsets.only(bottom: 4, top: 6, right: 4.0),
child: CommentCardActions(
commentView: widget.comment,
onVoteAction: (int commentId, int vote) => widget.onVoteAction(commentId, vote),
isEdit: widget.isOwnComment,
onSaveAction: widget.onSaveAction,
onDeleteAction: widget.onDeleteAction,
onReplyEditAction: widget.onReplyEditAction,
onReportAction: widget.onReportAction,
onViewSourceToggled: widget.onViewSourceToggled,
viewSource: widget.viewSource,
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0, bottom: 8.0),
child: ReplyToPreviewActions(
onViewSourceToggled: widget.onViewSourceToggled,
viewSource: widget.viewSource,
text: cleanCommentContent(widget.comment.comment),
if (widget.showReplyEditorButtons && widget.comment.comment.content.isNotEmpty == true) ...[
const Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: ThunderDivider(sliver: false, padding: false),
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0, bottom: 8.0),
child: ReplyToPreviewActions(
onViewSourceToggled: widget.onViewSourceToggled,
viewSource: widget.viewSource,
text: cleanCommentContent(widget.comment.comment),
),
),
],
],
],
),
),
);
}
Expand Down
24 changes: 11 additions & 13 deletions lib/shared/common_markdown_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,17 @@ class CommonMarkdownBody extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
!snapshot.hasData
? Container()
: snapshot.data == true
? ScalableImageWidget.fromSISource(
si: ScalableImageSource.fromSvgHttpUrl(uri),
)
: ImagePreview(
url: uri.toString(),
isExpandable: true,
isComment: isComment,
showFullHeightImages: true,
maxWidth: imageMaxWidth,
),
snapshot.data != true
? ImagePreview(
url: uri.toString(),
isExpandable: true,
isComment: isComment,
showFullHeightImages: true,
maxWidth: imageMaxWidth,
)
: ScalableImageWidget.fromSISource(
si: ScalableImageSource.fromSvgHttpUrl(uri),
)
],
),
);
Expand Down
15 changes: 8 additions & 7 deletions lib/shared/image_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:thunder/core/enums/image_caching_mode.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/colors.dart';

import 'package:thunder/utils/media/image.dart';

Expand Down Expand Up @@ -116,16 +117,15 @@ class _ImagePreviewState extends State<ImagePreview> {
cacheWidth: ((MediaQuery.of(context).size.width - 24) * View.of(context).devicePixelRatio.ceil()).toInt(),
loadStateChanged: (state) {
if (state.extendedImageLoadState == LoadState.loading) {
return Container();
return Container(color: getBackgroundColor(context));
}
if (state.extendedImageLoadState == LoadState.failed) {
return Text(
l10n.unableToLoadImageFrom(Uri.parse(widget.url!).host),
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.textTheme.bodyMedium?.color?.withOpacity(0.5),
),
return Container(
color: getBackgroundColor(context),
child: const Icon(Icons.image_not_supported_outlined),
);
}
return null;
},
)
: ExtendedImage.memory(
Expand All @@ -148,7 +148,7 @@ class _ImagePreviewState extends State<ImagePreview> {
cacheWidth: ((MediaQuery.of(context).size.width - 24) * View.of(context).devicePixelRatio.ceil()).toInt(),
loadStateChanged: (state) {
if (state.extendedImageLoadState == LoadState.loading) {
return Container();
return Container(color: getBackgroundColor(context));
}
if (state.extendedImageLoadState == LoadState.failed) {
return Text(
Expand All @@ -158,6 +158,7 @@ class _ImagePreviewState extends State<ImagePreview> {
),
);
}
return null;
},
),
TweenAnimationBuilder<double>(
Expand Down