From 3da1f79863e8d646a271a912e036f9c875206787 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Mon, 15 Jul 2024 16:07:21 -0400 Subject: [PATCH 1/7] Scroll to make space for toolbar --- lib/pages/chat/chat_event_list.dart | 1 + lib/pages/chat/events/message.dart | 18 ++++++++++---- lib/pages/chat/events/message_content.dart | 8 +++++- lib/pangea/widgets/chat/message_buttons.dart | 3 +++ lib/pangea/widgets/chat/message_toolbar.dart | 26 +++++++++++++++++--- lib/pangea/widgets/chat/overlay_message.dart | 3 +++ lib/pangea/widgets/igc/pangea_rich_text.dart | 7 +++++- 7 files changed, 56 insertions(+), 10 deletions(-) diff --git a/lib/pages/chat/chat_event_list.dart b/lib/pages/chat/chat_event_list.dart index 24508bb620..963a2c230f 100644 --- a/lib/pages/chat/chat_event_list.dart +++ b/lib/pages/chat/chat_event_list.dart @@ -168,6 +168,7 @@ class ChatEventList extends StatelessWidget { onSelect: controller.onSelectMessage, scrollToEventId: (String eventId) => controller.scrollToEventId(eventId), + scrollController: controller.scrollController, longPressSelect: controller.selectedEvents.isNotEmpty, // #Pangea selectedDisplayLang: diff --git a/lib/pages/chat/events/message.dart b/lib/pages/chat/events/message.dart index 3b2c1b2fb5..a1d04cb5ca 100644 --- a/lib/pages/chat/events/message.dart +++ b/lib/pages/chat/events/message.dart @@ -43,6 +43,7 @@ class Message extends StatelessWidget { final bool immersionMode; final bool definitions; final ChatController controller; + final ScrollController scrollController; // Pangea# final Color? avatarPresenceBackgroundColor; @@ -68,6 +69,7 @@ class Message extends StatelessWidget { required this.immersionMode, required this.definitions, required this.controller, + required this.scrollController, // Pangea# super.key, }); @@ -317,10 +319,12 @@ class Message extends StatelessWidget { padding: const EdgeInsets.only(left: 8), child: GestureDetector( // #Pangea - onTap: () => - toolbarController?.showToolbar(context), - onDoubleTap: () => - toolbarController?.showToolbar(context), + onTap: () => toolbarController?.showToolbar( + context, + scrollController, + ), + onDoubleTap: () => toolbarController + ?.showToolbar(context, scrollController), // Pangea# onLongPress: longPressSelect ? null @@ -443,6 +447,8 @@ class Message extends StatelessWidget { immersionMode: immersionMode, toolbarController: toolbarController, + scrollController: + scrollController, // Pangea# ), if (event.hasAggregatedEvents( @@ -588,7 +594,9 @@ class Message extends StatelessWidget { : MainAxisAlignment.start, children: [ if (pangeaMessageEvent?.showMessageButtons ?? false) - MessageButtons(toolbarController: toolbarController), + MessageButtons( + toolbarController: toolbarController, + scrollController: scrollController), MessageReactions(event, timeline), ], ), diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index 01ae471f80..ab6c601937 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -39,6 +39,7 @@ class MessageContent extends StatelessWidget { final bool immersionMode; final ToolbarDisplayController? toolbarController; final bool isOverlay; + final ScrollController scrollController; // Pangea# const MessageContent( @@ -52,6 +53,7 @@ class MessageContent extends StatelessWidget { required this.immersionMode, required this.toolbarController, this.isOverlay = false, + required this.scrollController, // Pangea# required this.borderRadius, }); @@ -299,6 +301,7 @@ class MessageContent extends StatelessWidget { style: messageTextStyle, pangeaMessageEvent: pangeaMessageEvent!, immersionMode: immersionMode, + scrollController: scrollController, toolbarController: toolbarController, ); } else if (pangeaMessageEvent != null) { @@ -322,7 +325,8 @@ class MessageContent extends StatelessWidget { toolbarController?.toolbar?.textSelection .onTextSelection(selection); }, - onTap: () => toolbarController?.showToolbar(context), + onTap: () => + toolbarController?.showToolbar(context, scrollController), contextMenuBuilder: (context, state) => (toolbarController?.highlighted ?? false) ? const SizedBox.shrink() @@ -331,10 +335,12 @@ class MessageContent extends StatelessWidget { textSelection: state, onDefine: () => toolbarController?.showToolbar( context, + scrollController, mode: MessageMode.definition, ), onListen: () => toolbarController?.showToolbar( context, + scrollController, mode: MessageMode.textToSpeech, ), ), diff --git a/lib/pangea/widgets/chat/message_buttons.dart b/lib/pangea/widgets/chat/message_buttons.dart index f7748675f2..7d35392981 100644 --- a/lib/pangea/widgets/chat/message_buttons.dart +++ b/lib/pangea/widgets/chat/message_buttons.dart @@ -4,15 +4,18 @@ import 'package:flutter/material.dart'; class MessageButtons extends StatelessWidget { final ToolbarDisplayController? toolbarController; + final ScrollController scrollController; const MessageButtons({ super.key, + required this.scrollController, this.toolbarController, }); void showActivity(BuildContext context) { toolbarController?.showToolbar( context, + scrollController, mode: MessageMode.practiceActivity, ); } diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 8d2d66b7d6..57c814bca9 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -59,7 +59,11 @@ class ToolbarDisplayController { ); } - void showToolbar(BuildContext context, {MessageMode? mode}) { + void showToolbar( + BuildContext context, + ScrollController scrollController, { + MessageMode? mode, + }) { bool toolbarUp = true; if (highlighted) return; if (controller.selectMode) { @@ -79,8 +83,23 @@ class ToolbarDisplayController { final Size transformTargetSize = (targetRenderBox as RenderBox).size; messageWidth = transformTargetSize.width; final Offset targetOffset = (targetRenderBox).localToGlobal(Offset.zero); - final double screenHeight = MediaQuery.of(context).size.height; - toolbarUp = targetOffset.dy >= screenHeight / 2; + // final double screenHeight = MediaQuery.of(context).size.height; + // If message is too close to top, make space for toolbar + if (targetOffset.dy < 360) { + // If chat can scroll up, do so + final scrollTo = scrollController.offset - targetOffset.dy + 360 + 118; + if (scrollTo >= 0) { + scrollController.animateTo( + scrollTo, + duration: FluffyThemes.animationDuration, + curve: FluffyThemes.animationCurve, + ); + } + // If cannot scroll up enough, show toolbar underneath instead + else { + toolbarUp = false; + } + } } final Widget overlayMessage = OverlayMessage( @@ -89,6 +108,7 @@ class ToolbarDisplayController { immersionMode: immersionMode, ownMessage: pangeaMessageEvent.ownMessage, toolbarController: this, + scrollController: scrollController, width: messageWidth, nextEvent: nextEvent, previousEvent: previousEvent, diff --git a/lib/pangea/widgets/chat/overlay_message.dart b/lib/pangea/widgets/chat/overlay_message.dart index 5f3d46c7e1..86ad9cfb85 100644 --- a/lib/pangea/widgets/chat/overlay_message.dart +++ b/lib/pangea/widgets/chat/overlay_message.dart @@ -21,6 +21,7 @@ class OverlayMessage extends StatelessWidget { final bool ownMessage; final ToolbarDisplayController toolbarController; final double? width; + final ScrollController scrollController; const OverlayMessage( this.event, { @@ -31,6 +32,7 @@ class OverlayMessage extends StatelessWidget { required this.immersionMode, required this.ownMessage, required this.toolbarController, + required this.scrollController, this.width, super.key, }); @@ -151,6 +153,7 @@ class OverlayMessage extends StatelessWidget { pangeaMessageEvent: pangeaMessageEvent, immersionMode: immersionMode, toolbarController: toolbarController, + scrollController: scrollController, isOverlay: true, ), if (event.hasAggregatedEvents( diff --git a/lib/pangea/widgets/igc/pangea_rich_text.dart b/lib/pangea/widgets/igc/pangea_rich_text.dart index abf583b3bd..4302807e64 100644 --- a/lib/pangea/widgets/igc/pangea_rich_text.dart +++ b/lib/pangea/widgets/igc/pangea_rich_text.dart @@ -21,12 +21,14 @@ class PangeaRichText extends StatefulWidget { final bool immersionMode; final ToolbarDisplayController? toolbarController; final TextStyle? style; + final ScrollController scrollController; const PangeaRichText({ super.key, required this.pangeaMessageEvent, required this.immersionMode, required this.toolbarController, + required this.scrollController, this.style, }); @@ -151,7 +153,8 @@ class PangeaRichTextState extends State { widget.toolbarController?.toolbar?.textSelection .onTextSelection(selection); }, - onTap: () => widget.toolbarController?.showToolbar(context), + onTap: () => widget.toolbarController + ?.showToolbar(context, widget.scrollController), enableInteractiveSelection: widget.toolbarController?.highlighted ?? false, contextMenuBuilder: (context, state) => @@ -162,10 +165,12 @@ class PangeaRichTextState extends State { textSelection: state, onDefine: () => widget.toolbarController?.showToolbar( context, + widget.scrollController, mode: MessageMode.definition, ), onListen: () => widget.toolbarController?.showToolbar( context, + widget.scrollController, mode: MessageMode.textToSpeech, ), ), From 6424f95855c4db2ab9f7f22159cac10b7f0dcfc8 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Tue, 16 Jul 2024 11:25:54 -0400 Subject: [PATCH 2/7] Fix some incorrect calculations --- lib/pangea/widgets/chat/message_toolbar.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 7794f46cf9..5f378657d8 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -86,8 +86,9 @@ class ToolbarDisplayController { // If message is too close to top, make space for toolbar if (targetOffset.dy < 360) { // If chat can scroll up, do so - final scrollTo = scrollController.offset - targetOffset.dy + 360 + 118; - if (scrollTo >= 0) { + final scrollTo = scrollController.offset - targetOffset.dy + 300; + if (scrollTo >= scrollController.position.minScrollExtent && + scrollTo <= scrollController.position.maxScrollExtent) { scrollController.animateTo( scrollTo, duration: FluffyThemes.animationDuration, From 9aa1c7725b6a945c2875ad0eed6cb00797456ed7 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Tue, 16 Jul 2024 11:53:09 -0400 Subject: [PATCH 3/7] Address some more edge cases --- lib/pangea/widgets/chat/message_toolbar.dart | 26 +++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 5f378657d8..f99758a437 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -86,7 +86,7 @@ class ToolbarDisplayController { // If message is too close to top, make space for toolbar if (targetOffset.dy < 360) { // If chat can scroll up, do so - final scrollTo = scrollController.offset - targetOffset.dy + 300; + var scrollTo = scrollController.offset - targetOffset.dy + 320; if (scrollTo >= scrollController.position.minScrollExtent && scrollTo <= scrollController.position.maxScrollExtent) { scrollController.animateTo( @@ -98,6 +98,30 @@ class ToolbarDisplayController { // If cannot scroll up enough, show toolbar underneath instead else { toolbarUp = false; + // Scroll down if need more space beneath message + final spaceBeneath = MediaQuery.of(context).size.height - + targetOffset.dy - + transformTargetSize.height; + if (spaceBeneath < 360) { + scrollTo = scrollController.offset + spaceBeneath - 320; + if (scrollTo >= scrollController.position.minScrollExtent && + scrollTo <= scrollController.position.maxScrollExtent) { + scrollController.animateTo( + scrollTo, + duration: FluffyThemes.animationDuration, + curve: FluffyThemes.animationCurve, + ); + } + // If can't scroll down enough, scroll up as much as possible and show toolbar above + else { + scrollController.animateTo( + scrollController.position.minScrollExtent, + duration: FluffyThemes.animationDuration, + curve: FluffyThemes.animationCurve, + ); + toolbarUp = true; + } + } } } } From e7167631d0f9ca62f90d5a305f14a35581084948 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Tue, 16 Jul 2024 12:02:31 -0400 Subject: [PATCH 4/7] More math corrections --- lib/pangea/widgets/chat/message_toolbar.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index f99758a437..41ae358d3c 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -84,7 +84,7 @@ class ToolbarDisplayController { final Offset targetOffset = (targetRenderBox).localToGlobal(Offset.zero); // final double screenHeight = MediaQuery.of(context).size.height; // If message is too close to top, make space for toolbar - if (targetOffset.dy < 360) { + if (targetOffset.dy < 320) { // If chat can scroll up, do so var scrollTo = scrollController.offset - targetOffset.dy + 320; if (scrollTo >= scrollController.position.minScrollExtent && @@ -102,7 +102,7 @@ class ToolbarDisplayController { final spaceBeneath = MediaQuery.of(context).size.height - targetOffset.dy - transformTargetSize.height; - if (spaceBeneath < 360) { + if (spaceBeneath < 320) { scrollTo = scrollController.offset + spaceBeneath - 320; if (scrollTo >= scrollController.position.minScrollExtent && scrollTo <= scrollController.position.maxScrollExtent) { From 19987c75a7c76b930d712ded9b71a57852585800 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Tue, 16 Jul 2024 16:07:42 -0400 Subject: [PATCH 5/7] Get rid of scrollcontroller chain --- lib/pages/chat/chat_event_list.dart | 1 - lib/pages/chat/events/message.dart | 13 ++-- lib/pages/chat/events/message_content.dart | 8 +-- lib/pangea/widgets/chat/message_buttons.dart | 3 - lib/pangea/widgets/chat/message_toolbar.dart | 75 ++++++++++---------- lib/pangea/widgets/chat/overlay_message.dart | 3 - lib/pangea/widgets/igc/pangea_rich_text.dart | 7 +- 7 files changed, 44 insertions(+), 66 deletions(-) diff --git a/lib/pages/chat/chat_event_list.dart b/lib/pages/chat/chat_event_list.dart index 963a2c230f..24508bb620 100644 --- a/lib/pages/chat/chat_event_list.dart +++ b/lib/pages/chat/chat_event_list.dart @@ -168,7 +168,6 @@ class ChatEventList extends StatelessWidget { onSelect: controller.onSelectMessage, scrollToEventId: (String eventId) => controller.scrollToEventId(eventId), - scrollController: controller.scrollController, longPressSelect: controller.selectedEvents.isNotEmpty, // #Pangea selectedDisplayLang: diff --git a/lib/pages/chat/events/message.dart b/lib/pages/chat/events/message.dart index a1d04cb5ca..45b60abd1a 100644 --- a/lib/pages/chat/events/message.dart +++ b/lib/pages/chat/events/message.dart @@ -43,7 +43,6 @@ class Message extends StatelessWidget { final bool immersionMode; final bool definitions; final ChatController controller; - final ScrollController scrollController; // Pangea# final Color? avatarPresenceBackgroundColor; @@ -69,7 +68,6 @@ class Message extends StatelessWidget { required this.immersionMode, required this.definitions, required this.controller, - required this.scrollController, // Pangea# super.key, }); @@ -321,10 +319,9 @@ class Message extends StatelessWidget { // #Pangea onTap: () => toolbarController?.showToolbar( context, - scrollController, ), - onDoubleTap: () => toolbarController - ?.showToolbar(context, scrollController), + onDoubleTap: () => + toolbarController?.showToolbar(context), // Pangea# onLongPress: longPressSelect ? null @@ -447,8 +444,6 @@ class Message extends StatelessWidget { immersionMode: immersionMode, toolbarController: toolbarController, - scrollController: - scrollController, // Pangea# ), if (event.hasAggregatedEvents( @@ -595,8 +590,8 @@ class Message extends StatelessWidget { children: [ if (pangeaMessageEvent?.showMessageButtons ?? false) MessageButtons( - toolbarController: toolbarController, - scrollController: scrollController), + toolbarController: toolbarController, + ), MessageReactions(event, timeline), ], ), diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index ab6c601937..01ae471f80 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -39,7 +39,6 @@ class MessageContent extends StatelessWidget { final bool immersionMode; final ToolbarDisplayController? toolbarController; final bool isOverlay; - final ScrollController scrollController; // Pangea# const MessageContent( @@ -53,7 +52,6 @@ class MessageContent extends StatelessWidget { required this.immersionMode, required this.toolbarController, this.isOverlay = false, - required this.scrollController, // Pangea# required this.borderRadius, }); @@ -301,7 +299,6 @@ class MessageContent extends StatelessWidget { style: messageTextStyle, pangeaMessageEvent: pangeaMessageEvent!, immersionMode: immersionMode, - scrollController: scrollController, toolbarController: toolbarController, ); } else if (pangeaMessageEvent != null) { @@ -325,8 +322,7 @@ class MessageContent extends StatelessWidget { toolbarController?.toolbar?.textSelection .onTextSelection(selection); }, - onTap: () => - toolbarController?.showToolbar(context, scrollController), + onTap: () => toolbarController?.showToolbar(context), contextMenuBuilder: (context, state) => (toolbarController?.highlighted ?? false) ? const SizedBox.shrink() @@ -335,12 +331,10 @@ class MessageContent extends StatelessWidget { textSelection: state, onDefine: () => toolbarController?.showToolbar( context, - scrollController, mode: MessageMode.definition, ), onListen: () => toolbarController?.showToolbar( context, - scrollController, mode: MessageMode.textToSpeech, ), ), diff --git a/lib/pangea/widgets/chat/message_buttons.dart b/lib/pangea/widgets/chat/message_buttons.dart index 7d35392981..f7748675f2 100644 --- a/lib/pangea/widgets/chat/message_buttons.dart +++ b/lib/pangea/widgets/chat/message_buttons.dart @@ -4,18 +4,15 @@ import 'package:flutter/material.dart'; class MessageButtons extends StatelessWidget { final ToolbarDisplayController? toolbarController; - final ScrollController scrollController; const MessageButtons({ super.key, - required this.scrollController, this.toolbarController, }); void showActivity(BuildContext context) { toolbarController?.showToolbar( context, - scrollController, mode: MessageMode.practiceActivity, ); } diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 41ae358d3c..477c64e5f0 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -59,8 +59,7 @@ class ToolbarDisplayController { } void showToolbar( - BuildContext context, - ScrollController scrollController, { + BuildContext context, { MessageMode? mode, }) { bool toolbarUp = true; @@ -82,46 +81,49 @@ class ToolbarDisplayController { final Size transformTargetSize = (targetRenderBox as RenderBox).size; messageWidth = transformTargetSize.width; final Offset targetOffset = (targetRenderBox).localToGlobal(Offset.zero); - // final double screenHeight = MediaQuery.of(context).size.height; - // If message is too close to top, make space for toolbar + + // If there is enough space above, procede as normal + // Else if there is enough space below, show toolbar underneath if (targetOffset.dy < 320) { - // If chat can scroll up, do so - var scrollTo = scrollController.offset - targetOffset.dy + 320; - if (scrollTo >= scrollController.position.minScrollExtent && - scrollTo <= scrollController.position.maxScrollExtent) { - scrollController.animateTo( - scrollTo, + final spaceBeneath = MediaQuery.of(context).size.height - + (targetOffset.dy + transformTargetSize.height); + if (spaceBeneath >= 320) { + toolbarUp = false; + } + + // See if it's possible to scroll up to make space + else if (controller.scrollController.offset - targetOffset.dy + 320 >= + controller.scrollController.position.minScrollExtent && + controller.scrollController.offset - targetOffset.dy + 320 <= + controller.scrollController.position.maxScrollExtent) { + controller.scrollController.animateTo( + controller.scrollController.offset - targetOffset.dy + 320, duration: FluffyThemes.animationDuration, curve: FluffyThemes.animationCurve, ); } - // If cannot scroll up enough, show toolbar underneath instead - else { + + // See if it's possible to scroll down to make space + else if (controller.scrollController.offset + spaceBeneath - 320 >= + controller.scrollController.position.minScrollExtent && + controller.scrollController.offset + spaceBeneath - 320 <= + controller.scrollController.position.maxScrollExtent) { + controller.scrollController.animateTo( + controller.scrollController.offset + spaceBeneath - 320, + duration: FluffyThemes.animationDuration, + curve: FluffyThemes.animationCurve, + ); toolbarUp = false; - // Scroll down if need more space beneath message - final spaceBeneath = MediaQuery.of(context).size.height - - targetOffset.dy - - transformTargetSize.height; - if (spaceBeneath < 320) { - scrollTo = scrollController.offset + spaceBeneath - 320; - if (scrollTo >= scrollController.position.minScrollExtent && - scrollTo <= scrollController.position.maxScrollExtent) { - scrollController.animateTo( - scrollTo, - duration: FluffyThemes.animationDuration, - curve: FluffyThemes.animationCurve, - ); - } - // If can't scroll down enough, scroll up as much as possible and show toolbar above - else { - scrollController.animateTo( - scrollController.position.minScrollExtent, - duration: FluffyThemes.animationDuration, - curve: FluffyThemes.animationCurve, - ); - toolbarUp = true; - } - } + } + + // If message is too big and can't scroll either way + // Scroll up as much as possible, and show toolbar above + else { + controller.scrollController.animateTo( + controller.scrollController.position.minScrollExtent, + duration: FluffyThemes.animationDuration, + curve: FluffyThemes.animationCurve, + ); } } } @@ -132,7 +134,6 @@ class ToolbarDisplayController { immersionMode: immersionMode, ownMessage: pangeaMessageEvent.ownMessage, toolbarController: this, - scrollController: scrollController, width: messageWidth, nextEvent: nextEvent, previousEvent: previousEvent, diff --git a/lib/pangea/widgets/chat/overlay_message.dart b/lib/pangea/widgets/chat/overlay_message.dart index 86ad9cfb85..5f3d46c7e1 100644 --- a/lib/pangea/widgets/chat/overlay_message.dart +++ b/lib/pangea/widgets/chat/overlay_message.dart @@ -21,7 +21,6 @@ class OverlayMessage extends StatelessWidget { final bool ownMessage; final ToolbarDisplayController toolbarController; final double? width; - final ScrollController scrollController; const OverlayMessage( this.event, { @@ -32,7 +31,6 @@ class OverlayMessage extends StatelessWidget { required this.immersionMode, required this.ownMessage, required this.toolbarController, - required this.scrollController, this.width, super.key, }); @@ -153,7 +151,6 @@ class OverlayMessage extends StatelessWidget { pangeaMessageEvent: pangeaMessageEvent, immersionMode: immersionMode, toolbarController: toolbarController, - scrollController: scrollController, isOverlay: true, ), if (event.hasAggregatedEvents( diff --git a/lib/pangea/widgets/igc/pangea_rich_text.dart b/lib/pangea/widgets/igc/pangea_rich_text.dart index 4302807e64..abf583b3bd 100644 --- a/lib/pangea/widgets/igc/pangea_rich_text.dart +++ b/lib/pangea/widgets/igc/pangea_rich_text.dart @@ -21,14 +21,12 @@ class PangeaRichText extends StatefulWidget { final bool immersionMode; final ToolbarDisplayController? toolbarController; final TextStyle? style; - final ScrollController scrollController; const PangeaRichText({ super.key, required this.pangeaMessageEvent, required this.immersionMode, required this.toolbarController, - required this.scrollController, this.style, }); @@ -153,8 +151,7 @@ class PangeaRichTextState extends State { widget.toolbarController?.toolbar?.textSelection .onTextSelection(selection); }, - onTap: () => widget.toolbarController - ?.showToolbar(context, widget.scrollController), + onTap: () => widget.toolbarController?.showToolbar(context), enableInteractiveSelection: widget.toolbarController?.highlighted ?? false, contextMenuBuilder: (context, state) => @@ -165,12 +162,10 @@ class PangeaRichTextState extends State { textSelection: state, onDefine: () => widget.toolbarController?.showToolbar( context, - widget.scrollController, mode: MessageMode.definition, ), onListen: () => widget.toolbarController?.showToolbar( context, - widget.scrollController, mode: MessageMode.textToSpeech, ), ), From 56de4ce2bc60c2f638a1f8add3c879ee89f529b2 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Thu, 18 Jul 2024 10:45:41 -0400 Subject: [PATCH 6/7] Minimize long message toolbar weirdness --- lib/pangea/widgets/chat/message_toolbar.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 477c64e5f0..16fb4571eb 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -152,9 +152,17 @@ class ToolbarDisplayController { ? CrossAxisAlignment.end : CrossAxisAlignment.start, children: [ - toolbarUp ? toolbar! : overlayMessage, + toolbarUp + // Column is limited to screen height + // If message portion is too tall, decrease toolbar height + // as necessary to prevent toolbar from acting strange + // Problems may still occur if toolbar height is decreased too much + ? Flexible( + child: toolbar!, + ) + : overlayMessage, const SizedBox(height: 6), - toolbarUp ? overlayMessage : toolbar!, + toolbarUp ? overlayMessage : Flexible(child: toolbar!), ], ); } catch (err) { From 328ce621af91c37d56258fe75c0118511843c405 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Fri, 19 Jul 2024 09:30:05 -0400 Subject: [PATCH 7/7] Get rid of Flexible redundancy --- lib/pangea/widgets/chat/message_toolbar.dart | 148 +++++++++---------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 16fb4571eb..5698b45c12 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -157,12 +157,10 @@ class ToolbarDisplayController { // If message portion is too tall, decrease toolbar height // as necessary to prevent toolbar from acting strange // Problems may still occur if toolbar height is decreased too much - ? Flexible( - child: toolbar!, - ) + ? toolbar! : overlayMessage, const SizedBox(height: 6), - toolbarUp ? overlayMessage : Flexible(child: toolbar!), + toolbarUp ? overlayMessage : toolbar!, ], ); } catch (err) { @@ -421,83 +419,85 @@ class MessageToolbarState extends State { @override Widget build(BuildContext context) { - return Material( - type: MaterialType.transparency, - child: Container( - padding: const EdgeInsets.all(10), - decoration: BoxDecoration( - color: Theme.of(context).cardColor, - border: Border.all( - width: 2, - color: Theme.of(context).colorScheme.primary, + return Flexible( + child: Material( + type: MaterialType.transparency, + child: Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + color: Theme.of(context).cardColor, + border: Border.all( + width: 2, + color: Theme.of(context).colorScheme.primary, + ), + borderRadius: const BorderRadius.all( + Radius.circular(25), + ), ), - borderRadius: const BorderRadius.all( - Radius.circular(25), + constraints: const BoxConstraints( + maxWidth: 300, + minWidth: 300, + maxHeight: 300, ), - ), - constraints: const BoxConstraints( - maxWidth: 300, - minWidth: 300, - maxHeight: 300, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Flexible( - child: SingleChildScrollView( - child: AnimatedSize( - duration: FluffyThemes.animationDuration, - child: Column( - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: toolbarContent ?? const SizedBox(), - ), - SizedBox(height: toolbarContent == null ? 0 : 20), - ], + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Flexible( + child: SingleChildScrollView( + child: AnimatedSize( + duration: FluffyThemes.animationDuration, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: toolbarContent ?? const SizedBox(), + ), + SizedBox(height: toolbarContent == null ? 0 : 20), + ], + ), ), ), ), - ), - Row( - mainAxisSize: MainAxisSize.min, - children: MessageMode.values.map((mode) { - if ([ - MessageMode.definition, - MessageMode.textToSpeech, - MessageMode.translation, - ].contains(mode) && - widget.pangeaMessageEvent.isAudioMessage) { - return const SizedBox.shrink(); - } - if (mode == MessageMode.speechToText && - !widget.pangeaMessageEvent.isAudioMessage) { - return const SizedBox.shrink(); - } - return Tooltip( - message: mode.tooltip(context), - child: IconButton( - icon: Icon(mode.icon), - color: mode.iconColor( - widget.pangeaMessageEvent, - currentMode, - context, + Row( + mainAxisSize: MainAxisSize.min, + children: MessageMode.values.map((mode) { + if ([ + MessageMode.definition, + MessageMode.textToSpeech, + MessageMode.translation, + ].contains(mode) && + widget.pangeaMessageEvent.isAudioMessage) { + return const SizedBox.shrink(); + } + if (mode == MessageMode.speechToText && + !widget.pangeaMessageEvent.isAudioMessage) { + return const SizedBox.shrink(); + } + return Tooltip( + message: mode.tooltip(context), + child: IconButton( + icon: Icon(mode.icon), + color: mode.iconColor( + widget.pangeaMessageEvent, + currentMode, + context, + ), + onPressed: () => updateMode(mode), + ), + ); + }).toList() + + [ + Tooltip( + message: L10n.of(context)!.more, + child: IconButton( + icon: const Icon(Icons.add_reaction_outlined), + onPressed: showMore, ), - onPressed: () => updateMode(mode), - ), - ); - }).toList() + - [ - Tooltip( - message: L10n.of(context)!.more, - child: IconButton( - icon: const Icon(Icons.add_reaction_outlined), - onPressed: showMore, ), - ), - ], - ), - ], + ], + ), + ], + ), ), ), );