Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to remove cancel button #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ class MyScene extends PureComponent {
PropTypes.number,
PropTypes.object
]),

/**
* Cancel button visiblity
*/
showCancelButton: PropTypes.bool,

/**
* text input
Expand Down Expand Up @@ -239,7 +244,8 @@ class MyScene extends PureComponent {
searchIconExpandedMargin: 10,
placeholderCollapsedMargin: 15,
placeholderExpandedMargin: 20,
shadowVisible: false
shadowVisible: false,
showCancelButton: true,
```

## LICENSE
Expand Down
56 changes: 35 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@ class Search extends PureComponent {
};

expandAnimation = () => {
const widthOffset = this.props.showCancelButton ? this.cancelButtonWidth : 10;

return new Promise((resolve, reject) => {
Animated.parallel([
Animated.timing(this.inputFocusWidthAnimated, {
toValue: this.contentWidth - this.cancelButtonWidth,
toValue: this.contentWidth - widthOffset,
duration: 200,
useNativeDriver: false
}).start(),
Expand Down Expand Up @@ -288,6 +290,8 @@ class Search extends PureComponent {
render() {
const isRtl = this.props.direction === 'rtl';
const styles = getStyles(this.props.inputHeight, isRtl);
const deleteIconPosition = this.props.showCancelButton ? 70 : 30;

return (
<Animated.View
ref="searchContainer"
Expand Down Expand Up @@ -389,34 +393,38 @@ class Search extends PureComponent {
this.props.positionRightDelete && {
[isRtl ? 'left' : 'right']: this.props.positionRightDelete
},
{ opacity: this.iconDeleteAnimated }
{ opacity: this.iconDeleteAnimated },
{ [isRtl ? 'left' : 'right']: deleteIconPosition},
]}
/>}
</TouchableWithoutFeedback>}

<TouchableOpacity onPress={this.onCancel}>
<Animated.View
style={[
styles.cancelButton,
this.props.cancelButtonStyle && this.props.cancelButtonStyle,
this.props.cancelButtonViewStyle && this.props.cancelButtonViewStyle,
{ [isRtl ? 'right' : 'left']: this.btnCancelAnimated },
]}
>
<Text
{
this.props.showCancelButton &&
<TouchableOpacity onPress={this.onCancel}>
<Animated.View
style={[
styles.cancelButtonText,
this.props.titleCancelColor && {
color: this.props.titleCancelColor
},
styles.cancelButton,
this.props.cancelButtonStyle && this.props.cancelButtonStyle,
this.props.cancelButtonTextStyle && this.props.cancelButtonTextStyle,
this.props.cancelButtonViewStyle && this.props.cancelButtonViewStyle,
{ [isRtl ? 'right' : 'left']: this.btnCancelAnimated },
]}
>
{this.cancelTitle}
</Text>
</Animated.View>
</TouchableOpacity>
<Text
style={[
styles.cancelButtonText,
this.props.titleCancelColor && {
color: this.props.titleCancelColor
},
this.props.cancelButtonStyle && this.props.cancelButtonStyle,
this.props.cancelButtonTextStyle && this.props.cancelButtonTextStyle,
]}
>
{this.cancelTitle}
</Text>
</Animated.View>
</TouchableOpacity>
}
</Animated.View>
);
}
Expand Down Expand Up @@ -555,6 +563,11 @@ Search.propTypes = {

cancelButtonViewStyle: PropTypes.oneOfType([PropTypes.object, ViewPropTypes.style]),

/**
* Cancel button visiblity
*/
showCancelButton: PropTypes.bool,

/**
* text input
*/
Expand Down Expand Up @@ -617,6 +630,7 @@ Search.defaultProps = {
shadowVisible: false,
useClearButton: true,
direction: 'ltr',
showCancelButton: true,
};

export default Search;