React Native Search Bar
The high-quality native iOS search bar for react native.
Getting Started
-
Installation
- Using npm:
npm install react-native-search-bar --save
- Using yarn:
yarn add react-native-search-bar
- Using npm:
-
Link
- Run
react-native link react-native-search-bar
- If linking fails, follow the
manual linking steps
- Run
Update
In your react native project, run
# npm
npm install react-native-search-bar@latest --save
# yarn
yarn add react-native-search-bar@latest
Usage
import SearchBar from 'react-native-search-bar'
<SearchBar
ref='searchBar'
placeholder='Search'
onChangeText={...}
onSearchButtonPress={...}
onCancelButtonPress={...}
/>
Managing the keyboard
- Show -
this.refs.searchBar.focus();
- Hide
this.refs.searchBar.blur();
- uses the iOSendEditing:true
method on the
underlyingUISearchBar
view.this.refs.searchBar.unFocus();
- callsresignFirstResponder
on the
UITextField
used by theUISearchBar
.
Examples
- Show the keyboard when the view loads:
componentDidMount() {
this.refs.searchBar.focus();
}
- Hide the keyboard when the user searches:
...
onSearchButtonPress={this.refs.searchBar.unFocus}
...