small fixes and refactoring

Change how NewWordOverlay is called and remove redundant variables, take repeat tokens/lemma out of newTokens on click
This commit is contained in:
avashilling 2025-07-02 16:58:41 -04:00
parent 1a08dda0ad
commit cec627386b
3 changed files with 24 additions and 26 deletions

View file

@ -569,7 +569,7 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
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<MessageSelectionOverlay>
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),
);
});
}
});

View file

@ -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<NewWordOverlay>
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<NewWordOverlay>
});
}
@override
void initState() {
super.initState();
if (widget.show) {
_initAndStartAnimation();
_animationStarted = true;
}
}
@override
void dispose() {
_overlayEntry?.remove();
@ -89,6 +79,7 @@ class _NewWordOverlayState extends State<NewWordOverlay>
}
void _showFlyingWidget() {
_overlayEntry?.remove(); // Remove any existing overlay
if (_controller == null || _xpScaleAnim == null || _fadeAnim == null) {
return;
}
@ -103,12 +94,16 @@ class _NewWordOverlayState extends State<NewWordOverlay>
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<NewWordOverlay>
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<NewWordOverlay>
@override
Widget build(BuildContext context) {
if (!widget.show && !_animationStarted) return widget.child;
return Stack(
children: [
widget.child,

View file

@ -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;
}
}