A React Native SearchBar
Clone SearchBar.js. This library depends on react-native-vector-icons. Please link it by following their installation guide.
All props are optional except height.
import React, { Component } from 'react';
import SearchBar from './SearchBar';
export default class ExampleComponent extends Component {
state = {
value = ''
}
render() {
return (
<SearchBar
value={this.state.value}
onBackPress={() => console.warn('On Focus')}
onClose={() => console.warn('On Close')}
placeholder="search"
onChangeText={value => this.setState({ value })}
/>
);
}
};
- TextInput props : SearchBar inherits all the properties of the
TextInput
onBackPress
: Optional function, Callback on back icon pressedonClose
: Optional function, Callback on close icon pressedalwaysShowBackButton
: Optional bool, use if you want to always show the back button instead of search, default isfalse
iconCloseName
: Optional string, use it to customize the close iconiconSearchName
: Optional string, use it to customize the search iconiconBackName
: Optional string, use it to customize the back iconiconCloseComponent
: Optional object, custom component for the close icon (overrides iconCloseName)iconSearchComponent
: Optional object, custom component for the search icon (overrides iconSearchName)iconBackComponent
: Optional object, custom component for the back icon (overrides iconBackName)iconColor
: Optional string, use it to define a different padding size, default is#737373
containerPadding
: Optional string, use it to define a different padding size, default is5
containerStyle
: Optional string, use it to pass your style to the containingView
searchBarStyle
: Optional string, use it to pass your style to thesearchBar
style
: Optional string, use it to pass your style to theTextInput
Contributions are welcome.
react-native-searchbar was inspired by react-native-material-design-searchbar Thanks ananddayalan.
MIT