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::{
50 share::{Kind, Share},50 share::{Kind, Share},
51 };51 };
52 use gpui_kit::{52 use gpui_kit::{
53- Anchor, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image,53+ Anchor, AnimationExt, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image,
54 InteractiveElement, IntoElement, ParentElement, ScrollHandle, StatefulInteractiveElement,54 InteractiveElement, IntoElement, ParentElement, ScrollHandle, StatefulInteractiveElement,
55 Styled, Subscription, Task, Window,55 Styled, Subscription, Task, Window,
56 assets::IconName,56 assets::IconName,
@@ -166,6 +166,7 @@ pub struct Chat {
166 scroll: ScrollHandle,166 scroll: ScrollHandle,
167 pub(super) jump: Option<Id>,167 pub(super) jump: Option<Id>,
168 highlight: Option<(Id, Instant)>,168 highlight: Option<(Id, Instant)>,
169+ glide: Option<(Id, gpui_kit::Pixels, Instant)>,
169 pub(super) view: View,170 pub(super) view: View,
170 pub(super) section: usize,171 pub(super) section: usize,
171 pub(super) username_input: Entity<InputState>,172 pub(super) username_input: Entity<InputState>,
@@ -423,6 +424,7 @@ impl Chat {
423 scroll: ScrollHandle::new(),424 scroll: ScrollHandle::new(),
424 jump: None,425 jump: None,
425 highlight: None,426 highlight: None,
427+ glide: None,
426 unread: HashMap::new(),428 unread: HashMap::new(),
427 unread_anchor: None,429 unread_anchor: None,
428 unseen: 0,430 unseen: 0,
@@ -902,7 +904,11 @@ impl Chat {
902 Some(index) => self.scroll_to_index(index),904 Some(index) => self.scroll_to_index(index),
903 None => self.scroll.scroll_to_bottom(),905 None => self.scroll.scroll_to_bottom(),
904 }906 }
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 {
906 self.jump_to_bottom();912 self.jump_to_bottom();
907 } else {913 } else {
908 self.unseen += 1;914 self.unseen += 1;
@@ -1786,12 +1792,16 @@ impl Yumush {
1786 )1792 )
1787 }1793 }
1788 1794
1789- fn message_list(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement {1795+ fn message_list(&self, entity: &Entity<Self>, palette: Palette) -> AnyElement {
1790 let divider = self1796 let divider = self
1791 .chat1797 .chat
1792 .unread_divider(self.user.as_ref().map(|user| user.id));1798 .unread_divider(self.user.as_ref().map(|user| user.id));
1793 let entity_scroll = entity.clone();1799 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()
1795 .id("chat_messages")1805 .id("chat_messages")
1796 .track_scroll(&self.chat.scroll)1806 .track_scroll(&self.chat.scroll)
1797 .flex()1807 .flex()
@@ -1885,6 +1895,17 @@ impl Yumush {
1885 entity,1895 entity,
1886 palette,1896 palette,
1887 );1897 );
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+ };
1888 if divider == Some(index) {1909 if divider == Some(index) {
1889 div()1910 div()
1890 .flex()1911 .flex()
@@ -1896,7 +1917,22 @@ impl Yumush {
1896 row1917 row
1897 }1918 }
1898 }),1919 }),
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()
1900 }1936 }
1901 1937
1902 fn composer(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> AnyElement {1938 fn composer(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> AnyElement {
@@ -3271,6 +3307,8 @@ fn members_column(
3271 }3307 }
3272 3308
3273 const OFFLINE: usize = 5;3309 const OFFLINE: usize = 5;
3310+const GLIDE: Duration = Duration::from_millis(240);
3311+const GLIDE_SLACK: Duration = Duration::from_millis(100);
3274 3312
3275 fn room_head(yumush: &Yumush, palette: Palette) -> Div {3313 fn room_head(yumush: &Yumush, palette: Palette) -> Div {
3276 let chat = &yumush.chat;3314 let chat = &yumush.chat;