diff --git a/lib/common/widgets/text/paragraph.dart b/lib/common/widgets/text/paragraph.dart index d0cc018c..f1a7bd15 100644 --- a/lib/common/widgets/text/paragraph.dart +++ b/lib/common/widgets/text/paragraph.dart @@ -557,13 +557,15 @@ class RenderParagraph extends RenderBox @override @protected bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { - if (_morePainter case final textPainter?) { - late final height = _textPainter.height; - if (position.dx < textPainter.width && - position.dy > height && - position.dy < height + textPainter.height) { - result.add(HitTestEntry(_moreTextSpan)); - return true; + if (_tapGestureRecognizer != null) { + if (_morePainter case final textPainter?) { + late final height = _textPainter.height; + if (position.dx < textPainter.width && + position.dy > height && + position.dy < height + textPainter.height) { + result.add(HitTestEntry(_moreTextSpan)); + return true; + } } } @@ -696,18 +698,18 @@ class RenderParagraph extends RenderBox VoidCallback? _onShowMore; set onShowMore(VoidCallback? onShowMore) { - _onShowMore = onShowMore; - _tapGestureRecognizer?.onTap = onShowMore; + if (_onShowMore != onShowMore) { + _onShowMore = onShowMore; + _tapGestureRecognizer?.onTap = onShowMore; + } } TapGestureRecognizer? _tapGestureRecognizer; - TapGestureRecognizer get _effectiveTapRecognizer => - _tapGestureRecognizer ??= TapGestureRecognizer()..onTap = _onShowMore; TextSpan get _moreTextSpan => TextSpan( style: text.style!.copyWith(color: _primary), text: '查看更多', - recognizer: _effectiveTapRecognizer, + recognizer: _tapGestureRecognizer, ); TextPainter? _morePainter; @@ -734,6 +736,9 @@ class RenderParagraph extends RenderBox size.height < textSize.height || _textPainter.didExceedMaxLines; if (didOverflowHeight) { + if (_onShowMore != null) { + _tapGestureRecognizer ??= TapGestureRecognizer()..onTap = _onShowMore; + } _morePainter ??= TextPainter( text: _moreTextSpan, textDirection: textDirection, diff --git a/lib/common/widgets/text/rich_text.dart b/lib/common/widgets/text/rich_text.dart index 97f96d55..319df88e 100644 --- a/lib/common/widgets/text/rich_text.dart +++ b/lib/common/widgets/text/rich_text.dart @@ -115,6 +115,7 @@ class RichText extends MultiChildRenderObjectWidget { this.selectionRegistrar, this.selectionColor, this.onShowMore, + required this.primary, }) : assert(maxLines == null || maxLines > 0), assert(selectionRegistrar == null || selectionColor != null), assert( @@ -229,6 +230,8 @@ class RichText extends MultiChildRenderObjectWidget { /// widgets. final Color? selectionColor; + final Color primary; + final VoidCallback? onShowMore; @override @@ -248,7 +251,7 @@ class RichText extends MultiChildRenderObjectWidget { locale: locale ?? Localizations.maybeLocaleOf(context), registrar: selectionRegistrar, selectionColor: selectionColor, - primary: Theme.of(context).colorScheme.primary, + primary: primary, onShowMore: onShowMore, ); } @@ -270,7 +273,7 @@ class RichText extends MultiChildRenderObjectWidget { ..locale = locale ?? Localizations.maybeLocaleOf(context) ..registrar = selectionRegistrar ..selectionColor = selectionColor - ..primary = Theme.of(context).colorScheme.primary + ..primary = primary ..onShowMore = onShowMore; } diff --git a/lib/common/widgets/text/text.dart b/lib/common/widgets/text/text.dart index 632e11f6..0da20a07 100644 --- a/lib/common/widgets/text/text.dart +++ b/lib/common/widgets/text/text.dart @@ -175,6 +175,7 @@ class Text extends StatelessWidget { this.textHeightBehavior, this.selectionColor, this.onShowMore, + required this.primary, }) : textSpan = null, assert( textScaler == null || textScaleFactor == null, @@ -213,6 +214,7 @@ class Text extends StatelessWidget { this.textHeightBehavior, this.selectionColor, this.onShowMore, + required this.primary, }) : data = null, assert( textScaler == null || textScaleFactor == null, @@ -351,6 +353,8 @@ class Text extends StatelessWidget { /// (semi-transparent grey). final Color? selectionColor; + final Color primary; + final VoidCallback? onShowMore; @override @@ -408,6 +412,7 @@ class Text extends StatelessWidget { text: data, children: textSpan != null ? [textSpan!] : null, ), + primary: primary, ), ); } else { @@ -440,6 +445,7 @@ class Text extends StatelessWidget { children: textSpan != null ? [textSpan!] : null, ), onShowMore: onShowMore, + primary: primary, ); } if (semanticsLabel != null || semanticsIdentifier != null) { @@ -537,6 +543,7 @@ class _SelectableTextContainer extends StatefulWidget { required this.textWidthBasis, this.textHeightBehavior, required this.selectionColor, + required this.primary, }); final TextSpan text; @@ -551,6 +558,7 @@ class _SelectableTextContainer extends StatefulWidget { final TextWidthBasis textWidthBasis; final ui.TextHeightBehavior? textHeightBehavior; final Color selectionColor; + final Color primary; @override State<_SelectableTextContainer> createState() => @@ -593,6 +601,7 @@ class _SelectableTextContainerState extends State<_SelectableTextContainer> { textHeightBehavior: widget.textHeightBehavior, selectionColor: widget.selectionColor, text: widget.text, + primary: widget.primary, ), ); } @@ -613,6 +622,7 @@ class _RichText extends StatelessWidget { required this.textWidthBasis, this.textHeightBehavior, required this.selectionColor, + required this.primary, }); final GlobalKey? textKey; @@ -628,6 +638,7 @@ class _RichText extends StatelessWidget { final TextWidthBasis textWidthBasis; final ui.TextHeightBehavior? textHeightBehavior; final Color selectionColor; + final Color primary; @override Widget build(BuildContext context) { @@ -647,6 +658,7 @@ class _RichText extends StatelessWidget { selectionRegistrar: registrar, selectionColor: selectionColor, text: text, + primary: primary, ); } } diff --git a/lib/pages/dynamics/widgets/content_panel.dart b/lib/pages/dynamics/widgets/content_panel.dart index ac43da37..90a77c1f 100644 --- a/lib/pages/dynamics/widgets/content_panel.dart +++ b/lib/pages/dynamics/widgets/content_panel.dart @@ -86,6 +86,7 @@ Widget content( richNodes, maxLines: isSave ? null : 6, onShowMore: () => PageUtils.pushDynDetail(item, isPush: true), + primary: theme.colorScheme.primary, ), if (pics?.isNotEmpty == true) CustomGridView( diff --git a/lib/pages/video/reply/widgets/reply_item_grpc.dart b/lib/pages/video/reply/widgets/reply_item_grpc.dart index 4d75ca55..8dbfa64c 100644 --- a/lib/pages/video/reply/widgets/reply_item_grpc.dart +++ b/lib/pages/video/reply/widgets/reply_item_grpc.dart @@ -274,6 +274,7 @@ class ReplyItemGrpc extends StatelessWidget { Padding( padding: padding, child: custom_text.Text.rich( + primary: theme.colorScheme.primary, style: TextStyle( height: 1.75, fontSize: theme.textTheme.bodyMedium!.fontSize,