forge
Explore
Log in

Don't you dare go Hollow

New message while at the bottom glides the chat scroll to it (240ms ease-out) and fades it in, instead of jumping

Browse files at this commit

4c33576384669fcebda6090ab9ef9532106dff62Ahmet Kaan GümüşParent: 9c09ad6
  • feat
    • new message while at the bottom glides the chat scroll to it (240ms ease-out) and fades it in, instead of jumping
Show full message
✨ feat: new message while at the bottom glides the chat scroll to it (240ms ease-out) and fades it in, instead of jumping
crates/client/src/gui/chat.rsmodified+43 -5
@@ -50,7 +50,7 @@ use common::{
5050 share::{Kind, Share},
5151 };
5252 use gpui_kit::{
53- Anchor, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image,
53+ Anchor, AnimationExt, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image,
5454 InteractiveElement, IntoElement, ParentElement, ScrollHandle, StatefulInteractiveElement,
5555 Styled, Subscription, Task, Window,
5656 assets::IconName,
@@ -166,6 +166,7 @@ pub struct Chat {
166166 scroll: ScrollHandle,
167167 pub(super) jump: Option<Id>,
168168 highlight: Option<(Id, Instant)>,
169+ glide: Option<(Id, gpui_kit::Pixels, Instant)>,
169170 pub(super) view: View,
170171 pub(super) section: usize,
171172 pub(super) username_input: Entity<InputState>,
@@ -423,6 +424,7 @@ impl Chat {
423424 scroll: ScrollHandle::new(),
424425 jump: None,
425426 highlight: None,
427+ glide: None,
426428 unread: HashMap::new(),
427429 unread_anchor: None,
428430 unseen: 0,
@@ -902,7 +904,11 @@ impl Chat {
902904 Some(index) => self.scroll_to_index(index),
903905 None => self.scroll.scroll_to_bottom(),
904906 }
905- } else if mine || !self.away() {
907+ } else if !self.away() {
908+ let newest = self.messages.last().map_or(0, |message| message.id);
909+ self.glide = Some((newest, self.scroll.offset().y, Instant::now()));
910+ self.unseen = 0;
911+ } else if mine {
906912 self.jump_to_bottom();
907913 } else {
908914 self.unseen += 1;
@@ -1786,12 +1792,16 @@ impl Yumush {
17861792 )
17871793 }
17881794
1789- fn message_list(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement {
1795+ fn message_list(&self, entity: &Entity<Self>, palette: Palette) -> AnyElement {
17901796 let divider = self
17911797 .chat
17921798 .unread_divider(self.user.as_ref().map(|user| user.id));
17931799 let entity_scroll = entity.clone();
1794- div()
1800+ let glide = self
1801+ .chat
1802+ .glide
1803+ .filter(|(_, _, at)| at.elapsed() < GLIDE + GLIDE_SLACK);
1804+ let list = div()
17951805 .id("chat_messages")
17961806 .track_scroll(&self.chat.scroll)
17971807 .flex()
@@ -1885,6 +1895,17 @@ impl Yumush {
18851895 entity,
18861896 palette,
18871897 );
1898+ let row = match glide {
1899+ Some((id, _, _)) if id == message.id => div()
1900+ .child(row)
1901+ .with_animation(
1902+ format!("chat_arrive_{id}"),
1903+ gpui_kit::Animation::new(GLIDE),
1904+ |row, delta| row.opacity(delta),
1905+ )
1906+ .into_any_element(),
1907+ _ => row,
1908+ };
18881909 if divider == Some(index) {
18891910 div()
18901911 .flex()
@@ -1896,7 +1917,22 @@ impl Yumush {
18961917 row
18971918 }
18981919 }),
1899- )
1920+ );
1921+ let Some((id, from, _)) = glide else {
1922+ return list.into_any_element();
1923+ };
1924+ let scroll = self.chat.scroll.clone();
1925+ list.with_animation(
1926+ format!("chat_glide_{id}"),
1927+ gpui_kit::Animation::new(GLIDE).with_easing(gpui_kit::ease_out_quint()),
1928+ move |list, delta| {
1929+ let to = -scroll.max_offset().y;
1930+ let x = scroll.offset().x;
1931+ scroll.set_offset(gpui_kit::point(x, from + (to - from) * delta));
1932+ list
1933+ },
1934+ )
1935+ .into_any_element()
19001936 }
19011937
19021938 fn composer(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> AnyElement {
@@ -3271,6 +3307,8 @@ fn members_column(
32713307 }
32723308
32733309 const OFFLINE: usize = 5;
3310+const GLIDE: Duration = Duration::from_millis(240);
3311+const GLIDE_SLACK: Duration = Duration::from_millis(100);
32743312
32753313 fn room_head(yumush: &Yumush, palette: Palette) -> Div {
32763314 let chat = &yumush.chat;