fix(chat): sent messages glide up from the composer like Telegram
- Own message rises 56 px from behind the input box and settles without bounce (320 ms) - Incoming messages only fade in (240 ms), no sideways slide Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -2,17 +2,12 @@ use std::time::Duration;
2
2
3
3
use gpui_kit::*;
4
4
5
pub const OWN_APPEAR: Duration = Duration::from_millis(420);
6
pub const INCOMING_APPEAR: Duration = Duration::from_millis(340);
5
pub const OWN_APPEAR: Duration = Duration::from_millis(320);
6
pub const INCOMING_APPEAR: Duration = Duration::from_millis(240);
7
7
8
const OWN_RISE: f32 = 16.;
9
const OWN_DRIFT: f32 = 8.;
10
const OWN_FADE_SHARE: f32 = 0.35;
11
const INCOMING_SLIDE: f32 = 18.;
12
const INCOMING_RISE: f32 = 4.;
13
const INCOMING_FADE_SHARE: f32 = 0.6;
14
const SPRING_DECAY: f32 = 6.;
15
const SPRING_FREQUENCY: f32 = 8.;
8
const OWN_RISE: f32 = 56.;
9
const OWN_START_OPACITY: f32 = 0.5;
10
const OWN_FADE_SHARE: f32 = 0.4;
16
11
17
12
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18
13
pub enum AppearKind {
@@ -40,21 +35,18 @@ pub fn appear_frame(kind: AppearKind, progress: f32) -> AppearFrame {
40
35
let progress = progress.clamp(0., 1.);
41
36
match kind {
42
37
AppearKind::Own => {
43
let remaining = 1. - spring_settle(progress);
38
let fade = ease_out_cubic(progress / OWN_FADE_SHARE);
44
39
AppearFrame {
45
offset_x: remaining * OWN_DRIFT,
46
offset_y: remaining * OWN_RISE,
47
opacity: ease_out_cubic(progress / OWN_FADE_SHARE),
48
}
49
}
50
AppearKind::Incoming => {
51
let remaining = 1. - ease_out_quint(progress);
52
AppearFrame {
53
offset_x: -remaining * INCOMING_SLIDE,
54
offset_y: remaining * INCOMING_RISE,
55
opacity: ease_out_cubic(progress / INCOMING_FADE_SHARE),
40
offset_x: 0.,
41
offset_y: (1. - ease_out_quart(progress)) * OWN_RISE,
42
opacity: OWN_START_OPACITY + (1. - OWN_START_OPACITY) * fade,
56
43
}
57
44
}
45
AppearKind::Incoming => AppearFrame {
46
offset_x: 0.,
47
offset_y: 0.,
48
opacity: ease_out_cubic(progress),
49
},
58
50
}
59
51
}
60
52
@@ -71,21 +63,12 @@ pub fn appear(body: Div, message_key: &str, kind: AppearKind) -> AnimationElemen
71
63
)
72
64
}
73
65
74
fn spring_settle(progress: f32) -> f32 {
75
if progress >= 1. {
76
return 1.;
77
}
78
let angle = SPRING_FREQUENCY * progress;
79
let ratio = SPRING_DECAY / SPRING_FREQUENCY;
80
1. - (-SPRING_DECAY * progress).exp() * (angle.cos() + ratio * angle.sin())
81
}
82
83
66
fn ease_out_cubic(progress: f32) -> f32 {
84
67
1. - (1. - progress.clamp(0., 1.)).powi(3)
85
68
}
86
69
87
fn ease_out_quint(progress: f32) -> f32 {
88
1. - (1. - progress.clamp(0., 1.)).powi(5)
70
fn ease_out_quart(progress: f32) -> f32 {
71
1. - (1. - progress.clamp(0., 1.)).powi(4)
89
72
}
90
73
91
74
#[cfg(test)]
@@ -93,13 +76,10 @@ mod tests {
93
76
use super::{AppearFrame, AppearKind, OWN_RISE, appear_frame};
94
77
95
78
#[test]
96
fn both_kinds_start_hidden_and_settle_on_the_resting_place() {
79
fn both_kinds_settle_on_the_resting_place() {
97
80
for kind in [AppearKind::Own, AppearKind::Incoming] {
98
let start = appear_frame(kind, 0.);
99
assert_eq!(start.opacity, 0.);
100
let end = appear_frame(kind, 1.);
101
81
assert_eq!(
102
end,
82
appear_frame(kind, 1.),
103
83
AppearFrame {
104
84
offset_x: 0.,
105
85
offset_y: 0.,
@@ -110,19 +90,21 @@ mod tests {
110
90
}
111
91
112
92
#[test]
113
fn own_messages_rise_from_the_bottom_right_and_overshoot_slightly() {
93
fn own_messages_glide_up_from_behind_the_composer_without_overshoot() {
114
94
let start = appear_frame(AppearKind::Own, 0.);
115
assert!(start.offset_x > 0. && start.offset_y > 0.);
116
let deepest = (1..100)
117
.map(|step| appear_frame(AppearKind::Own, step as f32 / 100.).offset_y)
118
.fold(f32::MAX, f32::min);
119
assert!(deepest < 0. && deepest > -OWN_RISE * 0.15);
95
assert_eq!(start.offset_y, OWN_RISE);
96
assert!((1..100).all(|step| {
97
let frame = appear_frame(AppearKind::Own, step as f32 / 100.);
98
frame.offset_y >= 0. && frame.offset_x == 0.
99
}));
120
100
}
121
101
122
102
#[test]
123
fn incoming_messages_slide_in_from_the_left_without_overshoot() {
124
let start = appear_frame(AppearKind::Incoming, 0.);
125
assert!(start.offset_x < 0.);
126
assert!((1..100).all(|step| appear_frame(AppearKind::Incoming, step as f32 / 100.).offset_x <= 0.));
103
fn incoming_messages_only_fade_in() {
104
assert_eq!(appear_frame(AppearKind::Incoming, 0.).opacity, 0.);
105
assert!((0..=100).all(|step| {
106
let frame = appear_frame(AppearKind::Incoming, step as f32 / 100.);
107
frame.offset_x == 0. && frame.offset_y == 0.
108
}));
127
109
}
128
110
}
@@ -2,17 +2,12 @@ use std::time::Duration;2
2
3
use gpui_kit::*;3
use gpui_kit::*;4
4
5
pub const OWN_APPEAR: Duration = Duration::from_millis(420);5
pub const OWN_APPEAR: Duration = Duration::from_millis(320);6
pub const INCOMING_APPEAR: Duration = Duration::from_millis(340);6
pub const INCOMING_APPEAR: Duration = Duration::from_millis(240);7
7
8
const OWN_RISE: f32 = 16.;8
const OWN_RISE: f32 = 56.;9
const OWN_DRIFT: f32 = 8.;9
const OWN_START_OPACITY: f32 = 0.5;10
const OWN_FADE_SHARE: f32 = 0.35;10
const OWN_FADE_SHARE: f32 = 0.4;11
const INCOMING_SLIDE: f32 = 18.;12
const INCOMING_RISE: f32 = 4.;13
const INCOMING_FADE_SHARE: f32 = 0.6;14
const SPRING_DECAY: f32 = 6.;15
const SPRING_FREQUENCY: f32 = 8.;16
11
17
#[derive(Debug, Clone, Copy, PartialEq, Eq)]12
#[derive(Debug, Clone, Copy, PartialEq, Eq)]18
pub enum AppearKind {13
pub enum AppearKind {@@ -40,21 +35,18 @@ pub fn appear_frame(kind: AppearKind, progress: f32) -> AppearFrame {40
let progress = progress.clamp(0., 1.);35
let progress = progress.clamp(0., 1.);41
match kind {36
match kind {42
AppearKind::Own => {37
AppearKind::Own => {43
let remaining = 1. - spring_settle(progress);38
let fade = ease_out_cubic(progress / OWN_FADE_SHARE);44
AppearFrame {39
AppearFrame {45
offset_x: remaining * OWN_DRIFT,40
offset_x: 0.,46
offset_y: remaining * OWN_RISE,41
offset_y: (1. - ease_out_quart(progress)) * OWN_RISE,47
opacity: ease_out_cubic(progress / OWN_FADE_SHARE),42
opacity: OWN_START_OPACITY + (1. - OWN_START_OPACITY) * fade,48
}49
}50
AppearKind::Incoming => {51
let remaining = 1. - ease_out_quint(progress);52
AppearFrame {53
offset_x: -remaining * INCOMING_SLIDE,54
offset_y: remaining * INCOMING_RISE,55
opacity: ease_out_cubic(progress / INCOMING_FADE_SHARE),56
}43
}57
}44
}45
AppearKind::Incoming => AppearFrame {46
offset_x: 0.,47
offset_y: 0.,48
opacity: ease_out_cubic(progress),49
},58
}50
}59
}51
}60
52
@@ -71,21 +63,12 @@ pub fn appear(body: Div, message_key: &str, kind: AppearKind) -> AnimationElemen71
)63
)72
}64
}73
65
74
fn spring_settle(progress: f32) -> f32 {75
if progress >= 1. {76
return 1.;77
}78
let angle = SPRING_FREQUENCY * progress;79
let ratio = SPRING_DECAY / SPRING_FREQUENCY;80
1. - (-SPRING_DECAY * progress).exp() * (angle.cos() + ratio * angle.sin())81
}82
83
fn ease_out_cubic(progress: f32) -> f32 {66
fn ease_out_cubic(progress: f32) -> f32 {84
1. - (1. - progress.clamp(0., 1.)).powi(3)67
1. - (1. - progress.clamp(0., 1.)).powi(3)85
}68
}86
69
87
fn ease_out_quint(progress: f32) -> f32 {70
fn ease_out_quart(progress: f32) -> f32 {88
1. - (1. - progress.clamp(0., 1.)).powi(5)71
1. - (1. - progress.clamp(0., 1.)).powi(4)89
}72
}90
73
91
#[cfg(test)]74
#[cfg(test)]@@ -93,13 +76,10 @@ mod tests {93
use super::{AppearFrame, AppearKind, OWN_RISE, appear_frame};76
use super::{AppearFrame, AppearKind, OWN_RISE, appear_frame};94
77
95
#[test]78
#[test]96
fn both_kinds_start_hidden_and_settle_on_the_resting_place() {79
fn both_kinds_settle_on_the_resting_place() {97
for kind in [AppearKind::Own, AppearKind::Incoming] {80
for kind in [AppearKind::Own, AppearKind::Incoming] {98
let start = appear_frame(kind, 0.);99
assert_eq!(start.opacity, 0.);100
let end = appear_frame(kind, 1.);101
assert_eq!(81
assert_eq!(102
end,82
appear_frame(kind, 1.),103
AppearFrame {83
AppearFrame {104
offset_x: 0.,84
offset_x: 0.,105
offset_y: 0.,85
offset_y: 0.,@@ -110,19 +90,21 @@ mod tests {110
}90
}111
91
112
#[test]92
#[test]113
fn own_messages_rise_from_the_bottom_right_and_overshoot_slightly() {93
fn own_messages_glide_up_from_behind_the_composer_without_overshoot() {114
let start = appear_frame(AppearKind::Own, 0.);94
let start = appear_frame(AppearKind::Own, 0.);115
assert!(start.offset_x > 0. && start.offset_y > 0.);95
assert_eq!(start.offset_y, OWN_RISE);116
let deepest = (1..100)96
assert!((1..100).all(|step| {117
.map(|step| appear_frame(AppearKind::Own, step as f32 / 100.).offset_y)97
let frame = appear_frame(AppearKind::Own, step as f32 / 100.);118
.fold(f32::MAX, f32::min);98
frame.offset_y >= 0. && frame.offset_x == 0.119
assert!(deepest < 0. && deepest > -OWN_RISE * 0.15);99
}));120
}100
}121
101
122
#[test]102
#[test]123
fn incoming_messages_slide_in_from_the_left_without_overshoot() {103
fn incoming_messages_only_fade_in() {124
let start = appear_frame(AppearKind::Incoming, 0.);104
assert_eq!(appear_frame(AppearKind::Incoming, 0.).opacity, 0.);125
assert!(start.offset_x < 0.);105
assert!((0..=100).all(|step| {126
assert!((1..100).all(|step| appear_frame(AppearKind::Incoming, step as f32 / 100.).offset_x <= 0.));106
let frame = appear_frame(AppearKind::Incoming, step as f32 / 100.);107
frame.offset_x == 0. && frame.offset_y == 0.108
}));127
}109
}128
}110
}