2024-03-06 01:57:59 +08:00
|
|
|
import { Strings } from "@core/i18n";
|
2024-05-23 01:41:43 +08:00
|
|
|
import { requireAssetIndex } from "@lib/api/assets";
|
2024-03-07 12:35:07 +08:00
|
|
|
import { TextInput } from "@ui/components/discord/Redesign";
|
2023-12-21 14:02:32 +08:00
|
|
|
import ErrorBoundary from "@ui/components/ErrorBoundary";
|
2024-03-07 09:09:31 +08:00
|
|
|
import { Image, View } from "react-native";
|
2023-04-15 02:05:35 +01:00
|
|
|
|
2024-02-23 15:11:35 +08:00
|
|
|
export interface SearchProps {
|
|
|
|
|
onChangeText?: (v: string) => void;
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
style?: import("react-native").TextStyle;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-21 03:30:21 +08:00
|
|
|
function SearchIcon() {
|
2024-05-23 01:41:43 +08:00
|
|
|
return <Image style={{ transform: [{ scale: 0.8 }] }} source={requireAssetIndex("search")} />;
|
2023-12-21 03:30:21 +08:00
|
|
|
}
|
2024-02-23 15:11:35 +08:00
|
|
|
|
2023-12-21 03:30:21 +08:00
|
|
|
export default ({ onChangeText, placeholder, style }: SearchProps) => {
|
|
|
|
|
const [query, setQuery] = React.useState("");
|
2024-03-06 01:57:59 +08:00
|
|
|
|
2023-12-21 03:30:21 +08:00
|
|
|
const onChange = (value: string) => {
|
|
|
|
|
setQuery(value);
|
|
|
|
|
onChangeText?.(value);
|
2024-03-06 01:57:59 +08:00
|
|
|
};
|
2023-04-15 02:05:35 +01:00
|
|
|
|
2023-12-21 03:30:21 +08:00
|
|
|
return <ErrorBoundary>
|
2024-03-07 09:09:31 +08:00
|
|
|
<View style={style}>
|
|
|
|
|
<TextInput
|
|
|
|
|
grow
|
|
|
|
|
isClearable
|
2023-12-21 03:30:21 +08:00
|
|
|
leadingIcon={SearchIcon}
|
2024-02-27 17:22:23 +08:00
|
|
|
placeholder={placeholder ?? Strings.SEARCH}
|
2023-12-21 03:30:21 +08:00
|
|
|
onChange={onChange}
|
|
|
|
|
returnKeyType={"search"}
|
|
|
|
|
size="md"
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
autoCorrect={false}
|
|
|
|
|
value={query}
|
|
|
|
|
/>
|
2024-03-07 09:09:31 +08:00
|
|
|
</View>
|
2024-03-06 01:57:59 +08:00
|
|
|
</ErrorBoundary>;
|
|
|
|
|
};
|