Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ class MyScene extends PureComponent {
onDelete: PropTypes.func,
afterDelete: PropTypes.func,

/**
* async await
* return a Promise
* beforeEndEditing, onEndEditing, afterEndEditing
*/
beforeEndEditing: PropTypes.func,
onEndEditing: PropTypes.func,
afterEndEditing: PropTypes.func,

/**
* boolean that defines if should trigger onCancel setting false
* will only trigger beforeEndEditing, onEndEditing, afterEndEditing
* with true, beforeCancel, onCancel and afterDelete too.
*/
cancelOnDismiss: PropTypes.bool

/**
* styles
*/
Expand Down Expand Up @@ -225,7 +241,8 @@ class MyScene extends PureComponent {
searchIconExpandedMargin: 10,
placeholderCollapsedMargin: 15,
placeholderExpandedMargin: 20,
shadowVisible: false
shadowVisible: false,
cancelOnDismiss: true,
```

## LICENSE
Expand Down
50 changes: 43 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Dimensions,
Keyboard,
Image,
View
ViewPropTypes
} from 'react-native';

const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
Expand Down Expand Up @@ -160,22 +160,42 @@ class Search extends PureComponent {
});
await this.setState({ keyword: '' });
this.props.onDelete && (await this.props.onDelete());
this.props.onChangeText && (await this.props.onChangeText(this.state.keyword));
this.props.afterDelete && (await this.props.afterDelete());
};

/**
* onEndEditting
* async await
*/
onEndEditing = async() => {
this.props.beforeEndEditing && (await this.props.beforeEndEditing());
this.props.onEndEditing && (await this.props.onEndEditing());
this.props.afterEndEditing && (await this.props.afterEndEditing());
}

/**
* onCancel
* async await
*/
onCancel = async () => {
onCancel = async (endEditing = false) => {
this.props.beforeCancel && (await this.props.beforeCancel());
if (endEditing)
this.props.beforeEndEditing && (await this.props.beforeEndEditing());

await this.setState({ keyword: '' });
await this.setState(prevState => {
return { expanded: !prevState.expanded };
});
await this.collapseAnimation(true);

this.props.onCancel && (await this.props.onCancel());
if (endEditing)
this.props.onEndEditing && (await this.props.onEndEditing());

this.props.afterCancel && (await this.props.afterCancel());
if (endEditing)
this.props.afterEndEditing && (await this.props.afterEndEditing());
};

expandAnimation = () => {
Expand Down Expand Up @@ -287,7 +307,7 @@ class Search extends PureComponent {
shadowRadius: this.props.shadowRadius
}
]}
onEndEditing={this.onCancel}
onEndEditing={this.props.cancelOnDismiss ? () => this.onCancel(true) : this.onEndEditing}
editable={this.props.editable}
value={this.state.keyword}
onChangeText={this.onChangeText}
Expand Down Expand Up @@ -435,7 +455,7 @@ const styles = {
color: '#fff'
}
};

/**
* Props
*/
Expand Down Expand Up @@ -480,6 +500,21 @@ Search.propTypes = {
onDelete: PropTypes.func,
afterDelete: PropTypes.func,

/**
* async await
* return a Promise
* beforeEndEditing, onEndEditing, afterEndEditing
*/
beforeEndEditing: PropTypes.func,
onEndEditing: PropTypes.func,
afterEndEditing: PropTypes.func,

/**
* boolean that defines if should trigger onCancel
* with
*/
cancelOnDismiss: PropTypes.bool,

/**
* styles
*/
Expand All @@ -491,13 +526,13 @@ Search.propTypes = {
inputStyle: PropTypes.oneOfType([
PropTypes.number,
PropTypes.object,
View.propTypes.style
ViewPropTypes.style
]),
cancelButtonStyle: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
onLayout: PropTypes.func,
cancelButtonStyle: View.propTypes.style,
cancelButtonStyle: ViewPropTypes.style,
cancelButtonTextStyle: Text.propTypes.style,
cancelButtonViewStyle: View.propTypes.style,
cancelButtonViewStyle: ViewPropTypes.style,

/**
* text input
Expand Down Expand Up @@ -543,6 +578,7 @@ Search.propTypes = {
Search.defaultProps = {
editable: true,
blurOnSubmit: true,
cancelOnDismiss: true,
keyboardShouldPersist: false,
searchIconCollapsedMargin: 25,
searchIconExpandedMargin: 10,
Expand Down