From 90adf436d31d29fbaa2005da3bbb8532bf7f6f8d Mon Sep 17 00:00:00 2001 From: Matthew <119624750+casualWaist@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:29:44 -0400 Subject: [PATCH] Choice quick click bug fixed 343 --- assets/pangea/bot_faces/pangea_bot.riv | Bin 10789 -> 11187 bytes lib/pages/chat/chat_input_row.dart | 4 - lib/pages/chat/chat_view.dart | 4 + .../choreographer/widgets/choice_array.dart | 97 ++++++++++++++---- lib/pangea/controllers/local_settings.dart | 3 +- lib/pangea/widgets/igc/span_card.dart | 2 +- 6 files changed, 83 insertions(+), 27 deletions(-) diff --git a/assets/pangea/bot_faces/pangea_bot.riv b/assets/pangea/bot_faces/pangea_bot.riv index 177b9b28fe53aa22a9bb986fbdd7a3e62dd71a09..94244a30f977bc7fadbcec98932ba3bff200374d 100644 GIT binary patch delta 533 zcmZ1)vN?RiIk8Yl<6H(QQ(gu+7e=@9zR4Cq4j-6P$GX9ULDIMaE}M1klsQ~>0V9(c zkRt$A%D~WI59A2KIh)Ult!3i#g{zjZb#mHVE*Z?p4zvZtnS4S?l}1*-QPN@7LA4s_ z4LqKl?5Uz+K&nSKo2n%;P2MfWHF>&*7Hxbo`GCglz#c{h1_uWQ%PvNCpTx@4A_YSR zdj{L7Kv5vU3?f)T1Pg;5gX45Yrg@AL{21J31EqmHmU)a9_`$rnKmlMB0mYanU(i&S TV4ughLmVOFz~BHfgpmONzpMoNT46%q(xtH91FJV)Hp=0cOVB$^5D+o72=InI@mm z)Sm3Ab<32&vWt=3C$TcMNWqZ7j=^y{Bg;I-34RQ2vl$scJhpj^7x=-vxj=yidyp9W l? choices; final void Function(int) onPressed; @@ -18,6 +17,7 @@ class ChoicesArray extends StatelessWidget { final int? selectedChoiceIndex; final String originalSpan; final String Function(int) uniqueKeyForLayerLink; + const ChoicesArray({ super.key, required this.isLoading, @@ -29,23 +29,49 @@ class ChoicesArray extends StatelessWidget { this.onLongPress, }); + @override + ChoicesArrayState createState() => ChoicesArrayState(); +} + +class ChoicesArrayState extends State { + bool interactionDisabled = false; + + void disableInteraction() { + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() { + interactionDisabled = true; + }); + }); + } + + void enableInteractions() { + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() { + interactionDisabled = false; + }); + }); + } + @override Widget build(BuildContext context) { final ThemeData theme = Theme.of(context); - return isLoading && (choices == null || choices!.length <= 1) - ? ItShimmer(originalSpan: originalSpan) + return widget.isLoading && (widget.choices == null || widget.choices!.length <= 1) + ? ItShimmer(originalSpan: widget.originalSpan) : Wrap( alignment: WrapAlignment.center, - children: choices + children: widget.choices ?.asMap() .entries .map( (entry) => ChoiceItem( theme: theme, - onLongPress: onLongPress, - onPressed: onPressed, + onLongPress: widget.onLongPress, + onPressed: widget.onPressed, entry: entry, - isSelected: selectedChoiceIndex == entry.key, + interactionDisabled: interactionDisabled, + enableInteraction: enableInteractions, + disableInteraction: disableInteraction, + isSelected: widget.selectedChoiceIndex == entry.key, ), ) .toList() ?? @@ -74,6 +100,9 @@ class ChoiceItem extends StatelessWidget { required this.onPressed, required this.entry, required this.isSelected, + required this.interactionDisabled, + required this.enableInteraction, + required this.disableInteraction, }); final MapEntry entry; @@ -81,6 +110,9 @@ class ChoiceItem extends StatelessWidget { final void Function(int p1)? onLongPress; final void Function(int p1) onPressed; final bool isSelected; + final bool interactionDisabled; + final VoidCallback enableInteraction; + final VoidCallback disableInteraction; @override Widget build(BuildContext context) { @@ -94,6 +126,8 @@ class ChoiceItem extends StatelessWidget { key: ValueKey(entry.value.text), selected: entry.value.color != null, isGold: entry.value.isGold, + enableInteraction: enableInteraction, + disableInteraction: disableInteraction, child: Container( margin: const EdgeInsets.all(2), padding: EdgeInsets.zero, @@ -128,8 +162,9 @@ class ChoiceItem extends StatelessWidget { ), ), onLongPress: - onLongPress != null ? () => onLongPress!(entry.key) : null, - onPressed: () => onPressed(entry.key), + onLongPress != null && !interactionDisabled + ? () => onLongPress!(entry.key) : null, + onPressed: interactionDisabled ? null : () => onPressed(entry.key), child: Text( entry.value.text, style: BotStyle.text(context), @@ -149,11 +184,15 @@ class ChoiceAnimationWidget extends StatefulWidget { final Widget child; final bool selected; final bool isGold; + final VoidCallback enableInteraction; + final VoidCallback disableInteraction; const ChoiceAnimationWidget({ super.key, required this.child, required this.selected, + required this.enableInteraction, + required this.disableInteraction, this.isGold = false, }); @@ -161,11 +200,13 @@ class ChoiceAnimationWidget extends StatefulWidget { ChoiceAnimationWidgetState createState() => ChoiceAnimationWidgetState(); } +enum AnimationState { ready, forward, reverse, finished } + class ChoiceAnimationWidgetState extends State with SingleTickerProviderStateMixin { late final AnimationController _controller; late final Animation _animation; - bool animationPlayed = false; + AnimationState animationState = AnimationState.ready; @override void initState() { @@ -193,17 +234,29 @@ class ChoiceAnimationWidgetState extends State ), ]).animate(_controller); - if (widget.selected && !animationPlayed) { + widget.enableInteraction(); + + if (widget.selected && animationState == AnimationState.ready) { + widget.disableInteraction(); _controller.forward(); - animationPlayed = true; - setState(() {}); + setState(() { + animationState = AnimationState.forward; + }); } _controller.addStatusListener((status) { - if (status == AnimationStatus.completed) { + if (status == AnimationStatus.completed && + animationState == AnimationState.forward) { _controller.reverse(); - } else if (status == AnimationStatus.dismissed) { - _controller.stop(); - _controller.reset(); + setState(() { + animationState = AnimationState.reverse; + }); + } + if (status == AnimationStatus.dismissed && + animationState == AnimationState.reverse) { + widget.enableInteraction(); + setState(() { + animationState = AnimationState.finished; + }); } }); } @@ -211,10 +264,12 @@ class ChoiceAnimationWidgetState extends State @override void didUpdateWidget(ChoiceAnimationWidget oldWidget) { super.didUpdateWidget(oldWidget); - if (widget.selected && !animationPlayed) { + if (widget.selected && animationState == AnimationState.ready) { + widget.disableInteraction(); _controller.forward(); - animationPlayed = true; - setState(() {}); + setState(() { + animationState = AnimationState.forward; + }); } } diff --git a/lib/pangea/controllers/local_settings.dart b/lib/pangea/controllers/local_settings.dart index 5984a7bf5..d6ae119a5 100644 --- a/lib/pangea/controllers/local_settings.dart +++ b/lib/pangea/controllers/local_settings.dart @@ -9,7 +9,8 @@ class LocalSettings { } bool userLanguageToolSetting(ToolSetting setting) => - _pangeaController.pStoreService.read(setting.toString()) ?? true; + _pangeaController.pStoreService.read(setting.toString()) + ?? setting != ToolSetting.itAutoPlay; // bool get userEnableIT => // _pangeaController.pStoreService.read(ToolSetting.interactiveTranslator.toString()) ?? true; diff --git a/lib/pangea/widgets/igc/span_card.dart b/lib/pangea/widgets/igc/span_card.dart index 3d6df9928..75738a687 100644 --- a/lib/pangea/widgets/igc/span_card.dart +++ b/lib/pangea/widgets/igc/span_card.dart @@ -138,7 +138,7 @@ class WordMatchContent extends StatelessWidget { .choices![index] .isBestCorrection ? BotExpression.gold - : BotExpression.nonGold + : BotExpression.surprised ), ); // if (controller.widget.scm.pangeaMatch.match.choices![index].type ==