项目
在 GitHub 查看
anhtuank7c/react-native-search-box
关于
一款简单、轻量、快速且灵活的搜索框,带有动画效果,灵感来自 iOS 搜索栏。
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文react-native-search-box
English | Tiếng Việt
An animated, iOS-style search bar for React Native. No dependencies, no native code. iOS, Android and web, with TypeScript types.
Documentation with live demos and copyable code →
![]() Filter a list |
![]() Live search |
![]() Contacts |
![]() Recent searches |
![]() In a header |
![]() Themed |
Also: playground, hide on scroll, minimal, right to left.
Installation
npm install react-native-search-box
Works in Expo Go, needs no linking. React 16.8 and React Native 0.60 or later.
Usage
import { useState } from 'react';
import { FlatList, Text, View } from 'react-native';
import Search from 'react-native-search-box';
const cities = ['Berlin', 'Hà Nội', 'Paris', 'Tokyo'];
export default function App() {
const [query, setQuery] = useState('');
return (
<View style={{ flex: 1 }}>
<Search value={query} onChangeText={setQuery} />
<FlatList
data={cities.filter((city) => city.toLowerCase().includes(query.toLowerCase()))}
keyboardShouldPersistTaps="handled"
renderItem={({ item }) => <Text style={{ padding: 16 }}>{item}</Text>}
keyExtractor={(city) => city}
/>
</View>
);
}
Search when typing stops
<Search searchDelay={350} onSearch={async (text) => setResults(await api.search(text))} />
Left aligned, without Cancel or animation
<Search placeholderAlign="left" showCancelButton={false} animated={false} />
In a row
<View style={{ flexDirection: 'row' }}>
<Avatar />
<Search containerStyle={{ flex: 1 }} />
</View>
Control it through a ref
const box = useRef<Search>(null);
await box.current?.focus('shoes');
await box.current?.search();
API
| Group | Props |
|---|---|
| Text | value defaultValue placeholder cancelTitle autoFocus editable textInputProps |
| Behavior | searchDelay showCancelButton useClearButton collapseOnBlur keyboardShouldPersist placeholderAlign animated animationDuration direction |
| Callback | onChangeText onSearch onFocus onBlur onDelete onCancel (with before* / after*) |
| Style | containerStyle inputStyle inputHeight backgroundColor iconSearch iconDelete … |
| Testing | testID inputTestID cancelButtonTestID clearButtonTestID |
Full reference: props, methods.
Upgrading from 0.0.20
Props, defaults and ref methods are kept. A few behaviors changed, see Migration and the changelog.
Help
Troubleshooting · Contributing · Security
License
探索相关项目
加载中…





