👽 Support server-side truncate content

This commit is contained in:
LittleSheep 2024-10-13 20:36:10 +08:00
parent 1fc84099fe
commit 1809f2557d
4 changed files with 21 additions and 88 deletions

View File

@ -65,7 +65,6 @@ class _PostDetailScreenState extends State<PostDetailScreen> {
isClickable: false,
isOverrideEmbedClickable: true,
isFullDate: true,
isFullContent: true,
isShowReply: false,
isContentSelectable: true,
padding: AppTheme.isLargeScreen(context)

View File

@ -31,13 +31,11 @@ class PostItem extends StatefulWidget {
final bool isShowEmbed;
final bool isOverrideEmbedClickable;
final bool isFullDate;
final bool isFullContent;
final bool isContentSelectable;
final bool showFeaturedReply;
final String? attachmentParent;
final EdgeInsets? padding;
final Color? backgroundColor;
final Function? onComment;
@ -51,12 +49,10 @@ class PostItem extends StatefulWidget {
this.isShowEmbed = true,
this.isOverrideEmbedClickable = false,
this.isFullDate = false,
this.isFullContent = false,
this.isContentSelectable = false,
this.showFeaturedReply = false,
this.attachmentParent,
this.padding,
this.backgroundColor,
this.onComment,
});
@ -76,8 +72,6 @@ class _PostItemState extends State<PostItem> {
super.initState();
}
double _contentHeight = 0;
@override
Widget build(BuildContext context) {
final List<String> attachments = item.body['attachments'] is List
@ -95,18 +89,12 @@ class _PostItemState extends State<PostItem> {
).paddingOnly(bottom: 8),
_PostHeaderWidget(
isCompact: widget.isCompact,
isFullDate: widget.isFullDate,
item: item,
).paddingSymmetric(horizontal: 12),
_PostHeaderDividerWidget(item: item).paddingSymmetric(horizontal: 12),
SizedContainer(
maxWidth: 640,
maxHeight: widget.isFullContent ? double.infinity : 80,
child: _MeasureSize(
onChange: (size) {
setState(() => _contentHeight = size.height);
},
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: MarkdownTextContent(
parentId: 'p${item.id}',
content: item.body['content'],
@ -118,9 +106,7 @@ class _PostItemState extends State<PostItem> {
right: 12,
bottom: hasAttachment ? 4 : 0,
),
),
),
if (_contentHeight >= 80 && !widget.isFullContent)
if (widget.item.body?['content_truncated'] == true)
Opacity(
opacity: 0.8,
child: InkWell(child: Text('readMore'.tr)),
@ -165,30 +151,20 @@ class _PostItemState extends State<PostItem> {
children: [
_PostHeaderWidget(
isCompact: widget.isCompact,
isFullDate: widget.isFullDate,
item: item,
),
_PostHeaderDividerWidget(item: item),
SizedContainer(
maxWidth: 640,
maxHeight: widget.isFullContent ? double.infinity : 320,
child: _MeasureSize(
onChange: (size) {
setState(() => _contentHeight = size.height);
},
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: MarkdownTextContent(
parentId: 'p${item.id}-embed',
content: item.body['content'],
isAutoWarp: item.type == 'story',
isSelectable: widget.isContentSelectable,
isLargeText:
item.type == 'article' && widget.isFullContent,
),
),
),
),
if (_contentHeight >= 320 && !widget.isFullContent)
if (widget.item.body?['content_truncated'] == true)
Opacity(
opacity: 0.8,
child: InkWell(child: Text('readMore'.tr)),
@ -593,10 +569,12 @@ class _PostFooterWidget extends StatelessWidget {
class _PostHeaderWidget extends StatelessWidget {
final bool isCompact;
final bool isFullDate;
final Post item;
const _PostHeaderWidget({
required this.isCompact,
required this.isFullDate,
required this.item,
});
@ -629,6 +607,7 @@ class _PostHeaderWidget extends StatelessWidget {
if (isCompact)
RelativeDate(
item.publishedAt?.toLocal() ?? DateTime.now(),
isFull: isFullDate,
).paddingOnly(top: 1),
],
),
@ -684,45 +663,3 @@ class _PostThumbnail extends StatelessWidget {
);
}
}
typedef _OnWidgetSizeChange = void Function(Size size);
class _MeasureSizeRenderObject extends RenderProxyBox {
Size? oldSize;
_OnWidgetSizeChange onChange;
_MeasureSizeRenderObject(this.onChange);
@override
void performLayout() {
super.performLayout();
Size newSize = child!.size;
if (oldSize == newSize) return;
oldSize = newSize;
WidgetsBinding.instance.addPostFrameCallback((_) {
onChange(newSize);
});
}
}
class _MeasureSize extends SingleChildRenderObjectWidget {
final _OnWidgetSizeChange onChange;
const _MeasureSize({
required this.onChange,
required Widget super.child,
});
@override
RenderObject createRenderObject(BuildContext context) {
return _MeasureSizeRenderObject(onChange);
}
@override
void updateRenderObject(
BuildContext context, covariant _MeasureSizeRenderObject renderObject) {
renderObject.onChange = onChange;
}
}

View File

@ -86,7 +86,6 @@ class PostListEntryWidget extends StatelessWidget {
isClickable: isNestedClickable,
showFeaturedReply: showFeaturedReply,
padding: padding,
backgroundColor: backgroundColor,
onComment: () {
AppRouter.instance
.pushNamed(

View File

@ -31,8 +31,6 @@ class PostOwnedListEntry extends StatelessWidget {
isClickable: false,
isShowReply: false,
isReactable: false,
isFullContent: isFullContent,
backgroundColor: backgroundColor,
).paddingSymmetric(vertical: 8),
],
),