修复搜索提示列表的显示时机问题

This commit is contained in:
lyswhut 2023-03-28 09:19:56 +08:00
parent 4534e2f9e7
commit d31b47e155
3 changed files with 14 additions and 5 deletions

View File

@ -10,3 +10,4 @@
### 修复 ### 修复
- 修复歌单排序列表滚动重置问题 - 修复歌单排序列表滚动重置问题
- 修复搜索提示列表的显示时机问题

View File

@ -46,7 +46,6 @@ export default forwardRef<TipListType, TipListProps>(({ onSearch }, ref) => {
searchTipListRef.current?.setHeight(height) searchTipListRef.current?.setHeight(height)
setSearchText(keyword) setSearchText(keyword)
if (keyword) { if (keyword) {
visibleListRef.current = true
setTipListInfo(keyword, searchState.temp_source) setTipListInfo(keyword, searchState.temp_source)
debounceTipSearch(keyword, searchState.temp_source, (list) => { debounceTipSearch(keyword, searchState.temp_source, (list) => {
if (keyword != searchState.tipListInfo.text) return if (keyword != searchState.tipListInfo.text) return

View File

@ -28,6 +28,7 @@ export default () => {
const listRef = useRef<ListType>(null) const listRef = useRef<ListType>(null)
const layoutHeightRef = useRef<number>(0) const layoutHeightRef = useRef<number>(0)
const searchInfo = useRef<SearchInfo>({ temp_source: 'kw', source: 'kw', searchType: 'music' }) const searchInfo = useRef<SearchInfo>({ temp_source: 'kw', source: 'kw', searchType: 'music' })
const timeoutRef = useRef<NodeJS.Timeout | null>(null)
useEffect(() => { useEffect(() => {
void getSearchSetting().then(info => { void getSearchSetting().then(info => {
@ -74,16 +75,24 @@ export default () => {
searchTipListRef.current?.search(text, layoutHeightRef.current) searchTipListRef.current?.search(text, layoutHeightRef.current)
}, 500) }, 500)
} }
const handleSearch: HeaderBarProps['onSearch'] = (text) => { const handleHideTipList = () => {
searchTipListRef.current?.search(text, layoutHeightRef.current) if (timeoutRef.current) {
clearTimeout(timeoutRef.current)
timeoutRef.current = null
}
searchTipListRef.current?.hide() searchTipListRef.current?.hide()
}
const handleSearch: HeaderBarProps['onSearch'] = (text) => {
handleHideTipList()
searchTipListRef.current?.search(text, layoutHeightRef.current)
headerBarRef.current?.setText(text) headerBarRef.current?.setText(text)
headerBarRef.current?.blur() headerBarRef.current?.blur()
void addHistoryWord(text) void addHistoryWord(text)
listRef.current?.loadList(text, searchInfo.current.source, searchInfo.current.searchType) listRef.current?.loadList(text, searchInfo.current.source, searchInfo.current.searchType)
} }
const handleShowTipList: HeaderBarProps['onShowTipList'] = () => { const handleShowTipList: HeaderBarProps['onShowTipList'] = () => {
setTimeout(() => { if (timeoutRef.current) clearTimeout(timeoutRef.current)
timeoutRef.current = setTimeout(() => {
searchTipListRef.current?.show(layoutHeightRef.current) searchTipListRef.current?.show(layoutHeightRef.current)
}, 500) }, 500)
} }
@ -95,7 +104,7 @@ export default () => {
onSourceChange={handleSourceChange} onSourceChange={handleSourceChange}
onTempSearch={handleTempSearch} onTempSearch={handleTempSearch}
onSearch={handleSearch} onSearch={handleSearch}
onHideTipList={() => searchTipListRef.current?.hide()} onHideTipList={handleHideTipList}
onShowTipList={handleShowTipList} onShowTipList={handleShowTipList}
/> />
<View style={styles.content} onLayout={handleLayout}> <View style={styles.content} onLayout={handleLayout}>