|
@@ -29,6 +29,7 @@ export default function Index() {
|
|
});
|
|
});
|
|
return res.data;
|
|
return res.data;
|
|
};
|
|
};
|
|
|
|
+ const [isInputting, setIsInputting] = useState(false);
|
|
const [totalCount, setTotalCount] = useState<number>(0);
|
|
const [totalCount, setTotalCount] = useState<number>(0);
|
|
const getKey = (pageIndex: number, previousPageData) => {
|
|
const getKey = (pageIndex: number, previousPageData) => {
|
|
if (pageIndex === 0)
|
|
if (pageIndex === 0)
|
|
@@ -48,14 +49,30 @@ export default function Index() {
|
|
revalidateOnMount: false
|
|
revalidateOnMount: false
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ // 修改搜索框的 onChange 和 onFocus/onBlur
|
|
const handleSearchBarChanged = (v: string) => {
|
|
const handleSearchBarChanged = (v: string) => {
|
|
setSearchValue(v);
|
|
setSearchValue(v);
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const handleFocus = () => {
|
|
|
|
+ setIsInputting(true);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const handleBlur = () => {
|
|
|
|
+ // 延迟一点时间,避免 blur 后立即隐藏,影响输入法
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ setIsInputting(false);
|
|
|
|
+ }, 100);
|
|
|
|
+ };
|
|
|
|
+
|
|
const handleClear = () => {
|
|
const handleClear = () => {
|
|
setSearchValue("");
|
|
setSearchValue("");
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ // 有联系人列表,或者搜索栏有值,说明是搜索结果,搜索结果有可能是 0 条记录
|
|
|
|
+ const showSearchBar = totalCount > 0 || !!searchValue.length || isInputting;
|
|
|
|
+
|
|
|
|
+
|
|
const onScrollToUpper = () => {
|
|
const onScrollToUpper = () => {
|
|
// 加载更多数据
|
|
// 加载更多数据
|
|
// 如果搜索框中有数据由不加载更多数据
|
|
// 如果搜索框中有数据由不加载更多数据
|
|
@@ -133,8 +150,7 @@ export default function Index() {
|
|
];
|
|
];
|
|
};
|
|
};
|
|
|
|
|
|
- // 有联系人列表,或者搜索栏有值,说明是搜索结果,搜索结果有可能是 0 条记录
|
|
|
|
- const showSearchBar = totalCount > 0 || !!searchValue.length
|
|
|
|
|
|
+
|
|
|
|
|
|
const renderContent = () => {
|
|
const renderContent = () => {
|
|
if (list?.length) {
|
|
if (list?.length) {
|
|
@@ -172,8 +188,10 @@ export default function Index() {
|
|
{showSearchBar && (
|
|
{showSearchBar && (
|
|
<SearchBar
|
|
<SearchBar
|
|
value={searchValue}
|
|
value={searchValue}
|
|
- onChange={(e) => handleSearchBarChanged(e)}
|
|
|
|
- onClear={() => handleClear()}
|
|
|
|
|
|
+ onChange={handleSearchBarChanged}
|
|
|
|
+ onFocus={handleFocus}
|
|
|
|
+ onBlur={handleBlur}
|
|
|
|
+ onClear={handleClear}
|
|
></SearchBar>
|
|
></SearchBar>
|
|
)}
|
|
)}
|
|
</View>
|
|
</View>
|