fix(chats): big emojis play once like Teams
- One loop when the emoji comes into view, one more on hover, then the still frame - Leaving and re-entering the window no longer replays it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -11,12 +11,8 @@ use crate::theme;
11
11
const EMOTICON_SIZE: f32 = 50.;
12
12
const GLYPH_SIZE: f32 = 40.;
13
13
const EMOTICON_GAP: f32 = 4.;
14
const APPEAR_LOOPS: u32 = 2;
15
const HOVER_LOOPS: u32 = 5;
16
17
14
struct Playback {
18
15
started: Option<Instant>,
19
loops: u32,
20
16
}
21
17
22
18
#[derive(IntoElement)]
@@ -47,21 +43,16 @@ impl RenderOnce for JumboEmoticon {
47
43
Some(Err(_)) => return glyph(&self.emoji),
48
44
None => return div().size(px(EMOTICON_SIZE)).into_any_element(),
49
45
};
50
let playback = window.use_keyed_state(self.id.clone(), cx, |_, _| Playback {
51
started: None,
52
loops: APPEAR_LOOPS,
53
});
46
let playback = window.use_keyed_state(self.id.clone(), cx, |_, _| Playback { started: None });
54
47
let now = Instant::now();
55
48
let active = window.is_window_active();
56
let (started, loops) = playback.update(cx, |playback, _| {
57
if !active {
58
playback.started = None;
49
let started = playback.update(cx, |playback, _| {
50
if active {
51
playback.started.get_or_insert(now);
59
52
}
60
let started = active.then(|| *playback.started.get_or_insert(now));
61
(started, playback.loops)
53
playback.started
62
54
});
63
let playing = started
64
.is_some_and(|started| now.duration_since(started) < resolved.loop_duration() * loops);
55
let playing = started.is_some_and(|started| now.duration_since(started) < resolved.loop_duration());
65
56
let image = if playing {
66
57
images.animated.clone()
67
58
} else {
@@ -76,7 +67,6 @@ impl RenderOnce for JumboEmoticon {
76
67
if *hovered {
77
68
playback.update(cx, |playback, cx| {
78
69
playback.started = Some(Instant::now());
79
playback.loops = HOVER_LOOPS;
80
70
cx.notify();
81
71
});
82
72
}
@@ -11,12 +11,8 @@ use crate::theme;11
const EMOTICON_SIZE: f32 = 50.;11
const EMOTICON_SIZE: f32 = 50.;12
const GLYPH_SIZE: f32 = 40.;12
const GLYPH_SIZE: f32 = 40.;13
const EMOTICON_GAP: f32 = 4.;13
const EMOTICON_GAP: f32 = 4.;14
const APPEAR_LOOPS: u32 = 2;15
const HOVER_LOOPS: u32 = 5;16
17
struct Playback {14
struct Playback {18
started: Option<Instant>,15
started: Option<Instant>,19
loops: u32,20
}16
}21
17
22
#[derive(IntoElement)]18
#[derive(IntoElement)]@@ -47,21 +43,16 @@ impl RenderOnce for JumboEmoticon {47
Some(Err(_)) => return glyph(&self.emoji),43
Some(Err(_)) => return glyph(&self.emoji),48
None => return div().size(px(EMOTICON_SIZE)).into_any_element(),44
None => return div().size(px(EMOTICON_SIZE)).into_any_element(),49
};45
};50
let playback = window.use_keyed_state(self.id.clone(), cx, |_, _| Playback {46
let playback = window.use_keyed_state(self.id.clone(), cx, |_, _| Playback { started: None });51
started: None,52
loops: APPEAR_LOOPS,53
});54
let now = Instant::now();47
let now = Instant::now();55
let active = window.is_window_active();48
let active = window.is_window_active();56
let (started, loops) = playback.update(cx, |playback, _| {49
let started = playback.update(cx, |playback, _| {57
if !active {50
if active {58
playback.started = None;51
playback.started.get_or_insert(now);59
}52
}60
let started = active.then(|| *playback.started.get_or_insert(now));53
playback.started61
(started, playback.loops)62
});54
});63
let playing = started55
let playing = started.is_some_and(|started| now.duration_since(started) < resolved.loop_duration());64
.is_some_and(|started| now.duration_since(started) < resolved.loop_duration() * loops);65
let image = if playing {56
let image = if playing {66
images.animated.clone()57
images.animated.clone()67
} else {58
} else {@@ -76,7 +67,6 @@ impl RenderOnce for JumboEmoticon {76
if *hovered {67
if *hovered {77
playback.update(cx, |playback, cx| {68
playback.update(cx, |playback, cx| {78
playback.started = Some(Instant::now());69
playback.started = Some(Instant::now());79
playback.loops = HOVER_LOOPS;80
cx.notify();70
cx.notify();81
});71
});82
}72
}