How the Telegram-style sticky day header works
masterThe library implements a Telegram-style sticky day header using two distinct elements that work together to create a seamless transition:
- Inline Separator: A date pill rendered within the message list (
Itemcomponent) that scrolls normally with the content. - Floating Header: A sticky overlay (
DayAnimated) that pins the date of the topmost visible day just below the navigation bar during active scrolling.
Key Behaviors
- Scroll-Gated Visibility: The header is hidden when the list is at rest. It fades in quickly when scrolling starts (including momentum) and fades out after motion stops.
- Slide Transition: When crossing a day boundary, the dates do not cross-fade. Instead, the new date slides into position (down from the top when scrolling up, or up from the bottom when scrolling down) while the previous date is pushed out.
- Handoff Logic: To prevent duplicate dates or flickering, the library uses a 'hard cutoff' handoff. The inline separator hides exactly when the floating header takes over at a specific pixel offset (
DAY_HANDOFF_OFFSET). - Top of History: When scrolling to the very top (e.g., triggering 'Load earlier'), the floating header hides to avoid overlapping with the loading indicator.
/* Conceptual Model Summary */
// 1. Inline Separator: Scrolls with content
// 2. Floating Header: Sticks to top during scroll
// Transition: Sliding (not fading) between dates
// Visibility: Only visible during active scroll/momentum