| 1 | export interface MaterialFabScrollState { |
| 2 | readonly anchor: number; |
| 3 | readonly expanded: boolean; |
| 4 | } |
| 5 | |
| 6 | /** Ignore small direction changes and overscroll; always show the label at the top. */ |
| 7 | export function updateMaterialFabScroll( |
| 8 | state: MaterialFabScrollState, |
| 9 | offset: number, |
| 10 | maxOffset: number, |
| 11 | ): MaterialFabScrollState { |
| 12 | const y = Math.max(0, Math.min(offset, Math.max(0, maxOffset))); |
| 13 | if (y <= 8) return { anchor: y, expanded: true }; |
| 14 | const anchor = state.expanded ? Math.min(state.anchor, y) : Math.max(state.anchor, y); |
| 15 | if (Math.abs(y - anchor) >= 12) return { anchor: y, expanded: !state.expanded }; |
| 16 | return { anchor, expanded: state.expanded }; |
| 17 | } |