diff --git a/publish/changeLog.md b/publish/changeLog.md index f31245de..2ef4a5e3 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -10,3 +10,4 @@ ### 修复 - 修复歌单排序列表滚动重置问题 +- 修复搜索提示列表的显示时机问题 diff --git a/src/screens/Home/Views/Search/TipList.tsx b/src/screens/Home/Views/Search/TipList.tsx index 23848573..c4b75daf 100644 --- a/src/screens/Home/Views/Search/TipList.tsx +++ b/src/screens/Home/Views/Search/TipList.tsx @@ -46,7 +46,6 @@ export default forwardRef(({ onSearch }, ref) => { searchTipListRef.current?.setHeight(height) setSearchText(keyword) if (keyword) { - visibleListRef.current = true setTipListInfo(keyword, searchState.temp_source) debounceTipSearch(keyword, searchState.temp_source, (list) => { if (keyword != searchState.tipListInfo.text) return diff --git a/src/screens/Home/Views/Search/index.tsx b/src/screens/Home/Views/Search/index.tsx index 19e8e48f..de0ac6e1 100644 --- a/src/screens/Home/Views/Search/index.tsx +++ b/src/screens/Home/Views/Search/index.tsx @@ -28,6 +28,7 @@ export default () => { const listRef = useRef(null) const layoutHeightRef = useRef(0) const searchInfo = useRef({ temp_source: 'kw', source: 'kw', searchType: 'music' }) + const timeoutRef = useRef(null) useEffect(() => { void getSearchSetting().then(info => { @@ -74,16 +75,24 @@ export default () => { searchTipListRef.current?.search(text, layoutHeightRef.current) }, 500) } - const handleSearch: HeaderBarProps['onSearch'] = (text) => { - searchTipListRef.current?.search(text, layoutHeightRef.current) + const handleHideTipList = () => { + if (timeoutRef.current) { + clearTimeout(timeoutRef.current) + timeoutRef.current = null + } searchTipListRef.current?.hide() + } + const handleSearch: HeaderBarProps['onSearch'] = (text) => { + handleHideTipList() + searchTipListRef.current?.search(text, layoutHeightRef.current) headerBarRef.current?.setText(text) headerBarRef.current?.blur() void addHistoryWord(text) listRef.current?.loadList(text, searchInfo.current.source, searchInfo.current.searchType) } const handleShowTipList: HeaderBarProps['onShowTipList'] = () => { - setTimeout(() => { + if (timeoutRef.current) clearTimeout(timeoutRef.current) + timeoutRef.current = setTimeout(() => { searchTipListRef.current?.show(layoutHeightRef.current) }, 500) } @@ -95,7 +104,7 @@ export default () => { onSourceChange={handleSourceChange} onTempSearch={handleTempSearch} onSearch={handleSearch} - onHideTipList={() => searchTipListRef.current?.hide()} + onHideTipList={handleHideTipList} onShowTipList={handleShowTipList} />