UNPKG

1.11 kBJavaScriptView Raw
1import React from 'react';
2import { withTheme } from '../config';
3import IOSSearchBar from './SearchBar-ios';
4import AndroidSearchBar from './SearchBar-android';
5import DefaultSearchBar from './SearchBar-default';
6const SEARCHBAR_COMPONENTS = {
7 ios: IOSSearchBar,
8 android: AndroidSearchBar,
9 default: DefaultSearchBar,
10};
11class SearchBar extends React.Component {
12 constructor() {
13 super(...arguments);
14 this.focus = () => {
15 this.searchbar.focus();
16 };
17 this.blur = () => {
18 this.searchbar.blur();
19 };
20 this.clear = () => {
21 this.searchbar.clear();
22 };
23 this.cancel = () => {
24 this.searchbar.cancel && this.searchbar.cancel();
25 };
26 }
27 render() {
28 const Component = SEARCHBAR_COMPONENTS[this.props.platform] || DefaultSearchBar;
29 return (<Component ref={(ref) => {
30 this.searchbar = ref;
31 }} {...this.props}/>);
32 }
33}
34SearchBar.defaultProps = {
35 platform: 'default',
36};
37export { SearchBar };
38export default withTheme(SearchBar, 'SearchBar');