初始化模版工程
This commit is contained in:
25
components/nova-sdk/hooks/useMessageScroll.ts
Normal file
25
components/nova-sdk/hooks/useMessageScroll.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useRef, useCallback } from 'react'
|
||||
import type { MessageListRef } from '../message-list'
|
||||
|
||||
/**
|
||||
* 消息滚动管理 Hook
|
||||
*/
|
||||
export function useMessageScroll() {
|
||||
const messageListRef = useRef<MessageListRef>(null)
|
||||
|
||||
const scrollToBottom = useCallback((behavior: ScrollBehavior = 'smooth') => {
|
||||
messageListRef.current?.scrollToBottom(behavior)
|
||||
}, [])
|
||||
|
||||
const scrollToBottomDelayed = useCallback((delay = 100, behavior: ScrollBehavior = 'smooth') => {
|
||||
setTimeout(() => {
|
||||
messageListRef.current?.scrollToBottom(behavior)
|
||||
}, delay)
|
||||
}, [])
|
||||
|
||||
return {
|
||||
messageListRef,
|
||||
scrollToBottom,
|
||||
scrollToBottomDelayed,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user