diff --git a/packages/fscomponents/src/components/SearchBar.tsx b/packages/fscomponents/src/components/SearchBar.tsx index 0e3abd0261..b876cc2dad 100644 --- a/packages/fscomponents/src/components/SearchBar.tsx +++ b/packages/fscomponents/src/components/SearchBar.tsx @@ -32,6 +32,7 @@ export interface SearchBarProps { onFocus?: (input: any, container: any) => void; onBlur?: (input: any, container: any) => void; onCancel?: () => void; + renderCancelButton?: () => React.ReactNode; // visibility showSearchIcon?: boolean; @@ -44,6 +45,7 @@ export interface SearchBarProps { cancelTitle?: string; searchIcon?: ImageURISource; locateIcon?: ImageURISource; + cancelImage?: ImageURISource; onLocateButtonPress?: () => void; // input @@ -58,6 +60,9 @@ export interface SearchBarProps { searchIconStyle?: StyleProp; locateIconStyle?: StyleProp; inputTextStyle?: StyleProp; + cancelImageStyle?: StyleProp; + cancelImageBoxStyle?: StyleProp; + cancelContainerStyle?: StyleProp; cancelButtonWidth?: number; cancelButtonAlwaysVisible?: boolean; @@ -303,24 +308,45 @@ export class SearchBar extends PureComponent { } renderCancelButton = () => { - const { cancelTitleStyle } = this.props; + const { + cancelContainerStyle, + cancelImage, + cancelImageBoxStyle, + cancelImageStyle, + cancelTitle, + cancelTitleStyle, + renderCancelButton + } = this.props; + const { cancelButtonWidth } = this.state; + if (renderCancelButton) { + return renderCancelButton(); + } + + const viewStyle = cancelButtonWidth ? { width: cancelButtonWidth } : null; + // if cancelButtonWidth is defined, parent width is defined, so just fill all the space + const cancelStyle = cancelButtonWidth ? { flex: 1 } : { width: kCancelButtonWidthDefault }; + const cancelImageBoxStyleInput = cancelImageBoxStyle ? cancelImageBoxStyle : null; + const touchableStyle = [S.rightButton, cancelStyle, cancelImageBoxStyleInput]; + return ( - + - - {this.props.cancelTitle || 'Cancel'} - + {cancelImage ? ( + + ) : ( + + {cancelTitle || 'Cancel'} + + )} );