refactor: More stable scroll to event

This commit is contained in:
krille-chan 2023-12-26 18:51:53 +01:00
parent 038cd9cb73
commit 7d112b1e18
No known key found for this signature in database
3 changed files with 21 additions and 4 deletions

View file

@ -367,6 +367,8 @@ class ChatController extends State<ChatPageWithRoom> {
return; return;
} }
String? scrollToEventIdMarker;
Future<void>? _setReadMarkerFuture; Future<void>? _setReadMarkerFuture;
void setReadMarker({String? eventId}) { void setReadMarker({String? eventId}) {
@ -912,6 +914,9 @@ class ChatController extends State<ChatPageWithRoom> {
}); });
return; return;
} }
setState(() {
scrollToEventIdMarker = eventId;
});
await scrollController.scrollToIndex( await scrollController.scrollToIndex(
eventIndex, eventIndex,
preferPosition: AutoScrollPosition.middle, preferPosition: AutoScrollPosition.middle,

View file

@ -119,6 +119,8 @@ class ChatEventList extends StatelessWidget {
'${event.senderFromMemoryOrFallback.mention} ', '${event.senderFromMemoryOrFallback.mention} ',
), ),
), ),
highlightMarker:
controller.scrollToEventIdMarker == event.eventId,
onSelect: controller.onSelectMessage, onSelect: controller.onSelectMessage,
scrollToEventId: (String eventId) => scrollToEventId: (String eventId) =>
controller.scrollToEventId(eventId), controller.scrollToEventId(eventId),

View file

@ -31,6 +31,7 @@ class Message extends StatelessWidget {
final bool longPressSelect; final bool longPressSelect;
final bool selected; final bool selected;
final Timeline timeline; final Timeline timeline;
final bool highlightMarker;
const Message( const Message(
this.event, { this.event, {
@ -44,6 +45,7 @@ class Message extends StatelessWidget {
required this.onSwipe, required this.onSwipe,
this.selected = false, this.selected = false,
required this.timeline, required this.timeline,
this.highlightMarker = false,
super.key, super.key,
}); });
@ -186,8 +188,19 @@ class Message extends StatelessWidget {
padding: const EdgeInsets.only(left: 8), padding: const EdgeInsets.only(left: 8),
child: Material( child: Material(
color: noBubble ? Colors.transparent : color, color: noBubble ? Colors.transparent : color,
borderRadius: borderRadius,
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
elevation: highlightMarker || selected ? 10 : 0,
shape: RoundedRectangleBorder(
borderRadius: borderRadius,
side: BorderSide(
width: highlightMarker || selected ? 1 : 0,
color: selected
? Theme.of(context).colorScheme.onBackground
: highlightMarker
? Theme.of(context).colorScheme.primary
: Colors.transparent,
),
),
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: borderRadius:
@ -393,9 +406,6 @@ class Message extends StatelessWidget {
child: Stack( child: Stack(
children: [ children: [
Container( Container(
color: selected
? Theme.of(context).colorScheme.primary.withAlpha(100)
: Colors.transparent,
constraints: const BoxConstraints( constraints: const BoxConstraints(
maxWidth: FluffyThemes.columnWidth * 2.5, maxWidth: FluffyThemes.columnWidth * 2.5,
), ),