From cec627386bd8036db464975bad7a2db10c1b37a8 Mon Sep 17 00:00:00 2001 From: avashilling <165050625+avashilling@users.noreply.github.com> Date: Wed, 2 Jul 2025 16:58:41 -0400 Subject: [PATCH] small fixes and refactoring Change how NewWordOverlay is called and remove redundant variables, take repeat tokens/lemma out of newTokens on click --- .../widgets/message_selection_overlay.dart | 7 +++-- .../widgets/word_zoom/new_word_overlay.dart | 30 ++++++++----------- .../widgets/word_zoom/word_zoom_widget.dart | 13 ++++---- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/lib/pangea/toolbar/widgets/message_selection_overlay.dart b/lib/pangea/toolbar/widgets/message_selection_overlay.dart index fc05ad1bd..ede1c3c5e 100644 --- a/lib/pangea/toolbar/widgets/message_selection_overlay.dart +++ b/lib/pangea/toolbar/widgets/message_selection_overlay.dart @@ -569,7 +569,7 @@ class MessageOverlayController extends State updateSelectedSpan(token.text); - Future.delayed(const Duration(seconds: 2), () { + Future.delayed(const Duration(milliseconds: 1700), () { if (isNewToken(token)) { MatrixState.pangeaController.putAnalytics.setState( AnalyticsStream( @@ -593,13 +593,16 @@ class MessageOverlayController extends State targetID: token.text.uniqueKey, ), ); - // Remove the token from newTokens so it is no longer highlighted as "new" + // Remove the token (and all tokens of same lemma but different form) from newTokens setState(() { newTokens.removeWhere( (t) => t.text.offset == token.text.offset && t.text.length == token.text.length, ); + newTokens.removeWhere( + (t) => t.lemma.text.equals(token.lemma.text), + ); }); } }); diff --git a/lib/pangea/toolbar/widgets/word_zoom/new_word_overlay.dart b/lib/pangea/toolbar/widgets/word_zoom/new_word_overlay.dart index b07f8d3f4..1a376b5f9 100644 --- a/lib/pangea/toolbar/widgets/word_zoom/new_word_overlay.dart +++ b/lib/pangea/toolbar/widgets/word_zoom/new_word_overlay.dart @@ -6,14 +6,12 @@ import 'package:flutter/material.dart'; class NewWordOverlay extends StatefulWidget { final Widget child; - final bool show; final Color overlayColor; final GlobalKey cardKey; const NewWordOverlay({ super.key, required this.child, - required this.show, required this.overlayColor, required this.cardKey, }); @@ -30,14 +28,15 @@ class _NewWordOverlayState extends State Size size = const Size(0, 0); Offset position = const Offset(0, 0); OverlayEntry? _overlayEntry; - bool _animationStarted = false; bool columnMode = false; Widget? get svg => ConstructLevelEnum.seeds.icon(); - void _initAndStartAnimation() { + @override + void initState() { + super.initState(); _controller = AnimationController( vsync: this, - duration: const Duration(milliseconds: 2000), + duration: const Duration(milliseconds: 1700), ); _xpScaleAnim = CurvedAnimation( parent: _controller!, @@ -56,15 +55,6 @@ class _NewWordOverlayState extends State }); } - @override - void initState() { - super.initState(); - if (widget.show) { - _initAndStartAnimation(); - _animationStarted = true; - } - } - @override void dispose() { _overlayEntry?.remove(); @@ -89,6 +79,7 @@ class _NewWordOverlayState extends State } void _showFlyingWidget() { + _overlayEntry?.remove(); // Remove any existing overlay if (_controller == null || _xpScaleAnim == null || _fadeAnim == null) { return; } @@ -103,12 +94,16 @@ class _NewWordOverlayState extends State t = ((_controller!.value) - 0.7) / 0.3; t = t.clamp(0.0, 1.0); } + //move starting position as seed grows so it stays centered final startX = position.dx + size.width / 2 - (37 * scale); final startY = position.dy + size.height / 2 + 20 - (37 * scale); + //end is top left if column mode (going towards vocab stats) or top right of card otherwise final endX = (columnMode) ? 0.0 : position.dx + size.width; final endY = (columnMode) ? 0.0 : position.dy + 30; final currentX = startX * (1 - t) + endX * t; final currentY = startY * (1 - t) + endY * t; + //Grows into frame, and then shrinks if going to top right so it matches card seed size + final seedSize = 75 * scale * ((!columnMode) ? fade : 1); return Positioned( left: currentX, @@ -118,9 +113,9 @@ class _NewWordOverlayState extends State child: Transform.rotate( angle: scale * 2 * pi, child: SizedBox( - //if going to top right, shrinks as it moves to match word card seed size - width: 75 * scale * ((!columnMode) ? fade : 1), - height: 75 * scale * ((!columnMode) ? fade : 1), + //if going to card top right, shrinks as it moves to match word card seed size + width: seedSize, + height: seedSize, child: svg ?? const SizedBox(), ), ), @@ -140,7 +135,6 @@ class _NewWordOverlayState extends State @override Widget build(BuildContext context) { - if (!widget.show && !_animationStarted) return widget.child; return Stack( children: [ widget.child, diff --git a/lib/pangea/toolbar/widgets/word_zoom/word_zoom_widget.dart b/lib/pangea/toolbar/widgets/word_zoom/word_zoom_widget.dart index a164cfd4e..8c00bcdcb 100644 --- a/lib/pangea/toolbar/widgets/word_zoom/word_zoom_widget.dart +++ b/lib/pangea/toolbar/widgets/word_zoom/word_zoom_widget.dart @@ -245,11 +245,12 @@ class WordZoomWidget extends StatelessWidget { ), ); - return NewWordOverlay( - show: wordIsNew, - overlayColor: overlayColor, - cardKey: cardKey, - child: card, - ); + return wordIsNew + ? NewWordOverlay( + overlayColor: overlayColor, + cardKey: cardKey, + child: card, + ) + : card; } }