1 | import React from 'react';
|
2 | import { withTheme } from '../config';
|
3 | import IOSSearchBar from './SearchBar-ios';
|
4 | import AndroidSearchBar from './SearchBar-android';
|
5 | import DefaultSearchBar from './SearchBar-default';
|
6 | const SEARCHBAR_COMPONENTS = {
|
7 | ios: IOSSearchBar,
|
8 | android: AndroidSearchBar,
|
9 | default: DefaultSearchBar,
|
10 | };
|
11 | class 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 | }
|
34 | SearchBar.defaultProps = {
|
35 | platform: 'default',
|
36 | };
|
37 | export { SearchBar };
|
38 | export default withTheme(SearchBar, 'SearchBar');
|