* A ThreadScrollButton displays a button to scroll to the bottom of a Chat thread.
({children}: ThreadScrollButtonProps)
| 397 | * A ThreadScrollButton displays a button to scroll to the bottom of a Chat thread. |
| 398 | */ |
| 399 | function ThreadScrollButton({children}: ThreadScrollButtonProps) { |
| 400 | let {isNearBottom, scrollToBottom, ...buttonProps} = useContext(ThreadScrollButtonContext); |
| 401 | let ref = useRef<HTMLDivElement>(null); |
| 402 | let isVisible = !isNearBottom; |
| 403 | let isExiting = useExitAnimation(ref, isVisible); |
| 404 | |
| 405 | if (!isVisible && !isExiting) { |
| 406 | return null; |
| 407 | } |
| 408 | |
| 409 | return ( |
| 410 | <ButtonContext.Provider |
| 411 | value={{slots: {[DEFAULT_SLOT]: {}, scroll: {onPress: scrollToBottom, ...buttonProps}}}}> |
| 412 | <ThreadScrollButtonInner domRef={ref} isExiting={isExiting}> |
| 413 | {children} |
| 414 | </ThreadScrollButtonInner> |
| 415 | </ButtonContext.Provider> |
| 416 | ); |
| 417 | } |
| 418 | |
| 419 | interface ThreadScrollButtonInnerProps { |
| 420 | domRef: RefObject<HTMLDivElement | null>; |
nothing calls this directly
no test coverage detected