From 4c33576384669fcebda6090ab9ef9532106dff62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 29 Nov 2026 07:25:22 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20new=20message=20while=20at?= =?UTF-8?q?=20the=20bottom=20glides=20the=20chat=20scroll=20to=20it=20(240?= =?UTF-8?q?ms=20ease-out)=20and=20fades=20it=20in,=20instead=20of=20jumpin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/gui/chat.rs | 48 +++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 5a2f030..cafc818 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -50,7 +50,7 @@ use common::{ share::{Kind, Share}, }; use gpui_kit::{ - Anchor, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image, + Anchor, AnimationExt, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image, InteractiveElement, IntoElement, ParentElement, ScrollHandle, StatefulInteractiveElement, Styled, Subscription, Task, Window, assets::IconName, @@ -166,6 +166,7 @@ pub struct Chat { scroll: ScrollHandle, pub(super) jump: Option, highlight: Option<(Id, Instant)>, + glide: Option<(Id, gpui_kit::Pixels, Instant)>, pub(super) view: View, pub(super) section: usize, pub(super) username_input: Entity, @@ -423,6 +424,7 @@ impl Chat { scroll: ScrollHandle::new(), jump: None, highlight: None, + glide: None, unread: HashMap::new(), unread_anchor: None, unseen: 0, @@ -902,7 +904,11 @@ impl Chat { Some(index) => self.scroll_to_index(index), None => self.scroll.scroll_to_bottom(), } - } else if mine || !self.away() { + } else if !self.away() { + let newest = self.messages.last().map_or(0, |message| message.id); + self.glide = Some((newest, self.scroll.offset().y, Instant::now())); + self.unseen = 0; + } else if mine { self.jump_to_bottom(); } else { self.unseen += 1; @@ -1786,12 +1792,16 @@ impl Yumush { ) } - fn message_list(&self, entity: &Entity, palette: Palette) -> impl IntoElement { + fn message_list(&self, entity: &Entity, palette: Palette) -> AnyElement { let divider = self .chat .unread_divider(self.user.as_ref().map(|user| user.id)); let entity_scroll = entity.clone(); - div() + let glide = self + .chat + .glide + .filter(|(_, _, at)| at.elapsed() < GLIDE + GLIDE_SLACK); + let list = div() .id("chat_messages") .track_scroll(&self.chat.scroll) .flex() @@ -1885,6 +1895,17 @@ impl Yumush { entity, palette, ); + let row = match glide { + Some((id, _, _)) if id == message.id => div() + .child(row) + .with_animation( + format!("chat_arrive_{id}"), + gpui_kit::Animation::new(GLIDE), + |row, delta| row.opacity(delta), + ) + .into_any_element(), + _ => row, + }; if divider == Some(index) { div() .flex() @@ -1896,7 +1917,22 @@ impl Yumush { row } }), - ) + ); + let Some((id, from, _)) = glide else { + return list.into_any_element(); + }; + let scroll = self.chat.scroll.clone(); + list.with_animation( + format!("chat_glide_{id}"), + gpui_kit::Animation::new(GLIDE).with_easing(gpui_kit::ease_out_quint()), + move |list, delta| { + let to = -scroll.max_offset().y; + let x = scroll.offset().x; + scroll.set_offset(gpui_kit::point(x, from + (to - from) * delta)); + list + }, + ) + .into_any_element() } fn composer(&self, entity: &Entity, palette: Palette, cx: &App) -> AnyElement { @@ -3271,6 +3307,8 @@ fn members_column( } const OFFLINE: usize = 5; +const GLIDE: Duration = Duration::from_millis(240); +const GLIDE_SLACK: Duration = Duration::from_millis(100); fn room_head(yumush: &Yumush, palette: Palette) -> Div { let chat = &yumush.chat;