Skip to content

Commit

Permalink
Close toolbar search on BackAndroid press
Browse files Browse the repository at this point in the history
  • Loading branch information
xotahal committed Oct 6, 2016
1 parent dbc8556 commit c6335be
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Toolbar/Toolbar.react.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { Component, PropTypes } from 'react';
import {
Animated,
BackAndroid,
findNodeHandle,
StyleSheet,
NativeModules,
Platform,
StyleSheet,
Text,
TextInput,
TouchableWithoutFeedback,
Expand Down Expand Up @@ -220,6 +222,10 @@ class Toolbar extends Component {
}
);
};
onSearchCloseRequested = () => {
this.onSearchClosePressed();
return true; // because we need to stop propagation
}
onSearchTextChanged = (value) => {
const { searchable } = this.props;

Expand All @@ -232,10 +238,16 @@ class Toolbar extends Component {
onSearchPressed = () => {
const { searchable } = this.props;

// on android it's typical that back button closes search input on toolbar
if (Platform.OS !== 'ios') {
BackAndroid.addEventListener('onSearchCloseRequested', this.onSearchCloseRequested);
}

if (searchable && isFunction(searchable.onSearchPressed)) {
searchable.onSearchPressed();
}


this.setState({
isSearchActive: true,
searchValue: '',
Expand All @@ -244,10 +256,15 @@ class Toolbar extends Component {
onSearchClosePressed = () => {
const { searchable } = this.props;

if (Platform.OS !== 'ios') {
BackAndroid.removeEventListener('onSearchCloseRequested', this.onSearchCloseRequested);
}

if (searchable && isFunction(searchable.onSearchClosed)) {
searchable.onSearchClosed();
}


this.setState({
isSearchActive: false,
searchValue: '',
Expand Down

0 comments on commit c6335be

Please sign in to comment.