From 9b2b223faf615a245d4d5b5c7c43eb60c51a1e04 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:57:50 +0900 Subject: [PATCH] =?UTF-8?q?=E7=9C=81=E7=95=A5=E3=81=95=E3=82=8C=E3=81=9F?= =?UTF-8?q?=E3=83=8E=E3=83=BC=E3=83=88=E3=82=92=E4=B8=80=E5=AE=9A=E3=81=AE?= =?UTF-8?q?=E8=A1=8C=E3=81=BE=E3=81=A7=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/view/common/misskey_notes/mfm_text.dart | 6 + .../common/misskey_notes/misskey_note.dart | 134 ++++++++---------- .../misskey_notes/misskey_notes_test.dart | 5 +- 3 files changed, 69 insertions(+), 76 deletions(-) diff --git a/lib/view/common/misskey_notes/mfm_text.dart b/lib/view/common/misskey_notes/mfm_text.dart index 616d951db..d40652f54 100644 --- a/lib/view/common/misskey_notes/mfm_text.dart +++ b/lib/view/common/misskey_notes/mfm_text.dart @@ -34,6 +34,8 @@ class MfmText extends ConsumerStatefulWidget { final List prefixSpan; final Function(MisskeyEmojiData)? onEmojiTap; final bool isEnableAnimatedMFM; + final TextOverflow? overflow; + final int? maxLines; const MfmText({ super.key, @@ -47,6 +49,8 @@ class MfmText extends ConsumerStatefulWidget { this.prefixSpan = const [], this.onEmojiTap, this.isEnableAnimatedMFM = true, + this.overflow, + this.maxLines, }) : assert(mfmText != null || mfmNode != null); @override @@ -165,6 +169,8 @@ class MfmTextState extends ConsumerState { suffixSpan: widget.suffixSpan, prefixSpan: widget.prefixSpan, isUseAnimation: widget.isEnableAnimatedMFM, + overflow: widget.overflow, + maxLines: widget.maxLines, ); } } diff --git a/lib/view/common/misskey_notes/misskey_note.dart b/lib/view/common/misskey_notes/misskey_note.dart index 45ac25b83..ad320e022 100644 --- a/lib/view/common/misskey_notes/misskey_note.dart +++ b/lib/view/common/misskey_notes/misskey_note.dart @@ -418,84 +418,68 @@ class MisskeyNoteState extends ConsumerState { ], if (displayNote.cw == null || displayNote.cw != null && isCwOpened) ...[ - if (isReactionedRenote) - SimpleMfmText( - "${(displayNote.text ?? "").substring(0, min((displayNote.text ?? "").length, 50))}..." - .replaceAll("\n\n", "\n"), - isNyaize: displayNote.user.isCat, - emojis: displayNote.emojis, - suffixSpan: [ - WidgetSpan( - child: InNoteButton( - onPressed: () { - ref - .read(notesProvider( - AccountScope.of(context))) - .updateNoteStatus( - widget.note.id, - (status) => status.copyWith( - isReactionedRenote: !status - .isReactionedRenote), - ); - }, - child: const Text("続きを表示"), + MfmText( + mfmNode: displayTextNodes, + host: displayNote.user.host, + emoji: displayNote.emojis, + isNyaize: displayNote.user.isCat, + isEnableAnimatedMFM: ref + .read(generalSettingsRepositoryProvider) + .settings + .enableAnimatedMFM, + onEmojiTap: (emojiData) async => + await reactionControl( + ref, + context, + displayNote, + requestEmoji: emojiData, + ), + overflow: TextOverflow.clip, + suffixSpan: [ + if (!isEmptyRenote && + displayNote.renoteId != null && + (widget.recursive == 2 || + widget.isForceUnvisibleRenote)) + TextSpan( + text: " RN:...", + style: TextStyle( + color: Theme.of(context).primaryColor, + fontStyle: FontStyle.italic, ), - ) - ], - ) - else ...[ - if (isLongVisible) - MfmText( - mfmNode: displayTextNodes, - host: displayNote.user.host, - emoji: displayNote.emojis, - isNyaize: displayNote.user.isCat, - isEnableAnimatedMFM: ref - .read(generalSettingsRepositoryProvider) - .settings - .enableAnimatedMFM, - onEmojiTap: (emojiData) async => - await reactionControl( - ref, context, displayNote, - requestEmoji: emojiData), - suffixSpan: [ - if (!isEmptyRenote && - displayNote.renoteId != null && - (widget.recursive == 2 || - widget.isForceUnvisibleRenote)) - TextSpan( - text: " RN:...", - style: TextStyle( - color: Theme.of(context).primaryColor, - fontStyle: FontStyle.italic, - ), - ), - ], - ) - else - SimpleMfmText( - "${(displayNote.text ?? "").substring(0, min((displayNote.text ?? "").length, 150))}..." - .replaceAll("\n\n", "\n"), - emojis: displayNote.emojis, - isNyaize: displayNote.user.isCat, - suffixSpan: [ - WidgetSpan( - child: InNoteButton( - onPressed: () { - ref - .read(notesProvider( - AccountScope.of(context))) - .updateNoteStatus( - widget.note.id, - (status) => status.copyWith( - isLongVisible: !status - .isLongVisible)); - }, - child: const Text("続きを表示"), + ), + ], + maxLines: isReactionedRenote + ? 1 + : isLongVisible + ? null + : 10, + ), + if (isReactionedRenote || !isLongVisible) + Center( + child: InNoteButton( + onPressed: () { + final repository = ref.read( + notesProvider( + AccountScope.of(context), ), - ) - ], + ); + repository.updateNoteStatus( + widget.note.id, + (status) => isReactionedRenote + ? status.copyWith( + isReactionedRenote: + !status.isReactionedRenote, + ) + : status.copyWith( + isLongVisible: + !status.isLongVisible, + ), + ); + }, + child: const Text("続きを表示"), ), + ), + if (!isReactionedRenote) ...[ MisskeyFileView( files: displayNote.files, height: 200 * diff --git a/test/view/common/misskey_notes/misskey_notes_test.dart b/test/view/common/misskey_notes/misskey_notes_test.dart index 5da4e8d60..1e75a5458 100644 --- a/test/view/common/misskey_notes/misskey_notes_test.dart +++ b/test/view/common/misskey_notes/misskey_notes_test.dart @@ -175,9 +175,12 @@ System.out.println("@ai uneune"); note: TestData.note1.copyWith(text: longText), )); await tester.pumpAndSettle(); - expect(find.textContaining(longText, findRichText: true), findsNothing); await tester.tap(find.text("続きを表示")); await tester.pumpAndSettle(); + expect( + find.text("続きを表示"), + findsNothing, + ); expect( find.textContaining(longText, findRichText: true), findsOneWidget); });