Skip to content

Commit

Permalink
Added containerStyle props for platform specific searchbars (#999)
Browse files Browse the repository at this point in the history
* Added containerBgColor and inputBgColor props for searchbar

* Added inputContainerStyle prop for searchbar

* minor changes in test for searchbar

* Added test
  • Loading branch information
XeeshanAnsari authored and xavier-villelegier committed Mar 27, 2018
1 parent 3f9faed commit fdfaa09
Show file tree
Hide file tree
Showing 9 changed files with 3,418 additions and 1,254 deletions.
4,372 changes: 3,263 additions & 1,109 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/searchbar/SearchBar-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SearchBar extends Component {
leftIcon,
leftIconContainerStyle,
rightIconContainerStyle,
inputContainerStyle,
inputStyle,
noIcon,
showLoading,
Expand All @@ -82,15 +83,15 @@ class SearchBar extends Component {
/>
);
return (
<View style={styles.container}>
<View style={[styles.container, containerStyle]}>
<Input
{...attributes}
onFocus={this.onFocus}
onBlur={this.onBlur}
onChangeText={this.onChangeText}
ref={input => (this.input = input)}
inputStyle={[styles.input, inputStyle]}
containerStyle={[styles.inputContainer, containerStyle]}
containerStyle={[styles.inputContainer, inputContainerStyle]}
leftIcon={noIcon ? undefined : leftIcon ? leftIcon : searchIcon}
leftIconContainerStyle={[
styles.leftIconContainerStyle,
Expand Down Expand Up @@ -137,6 +138,7 @@ SearchBar.propTypes = {
leftIcon: PropTypes.object,
leftIconContainerStyle: ViewPropTypes.style,
rightIconContainerStyle: ViewPropTypes.style,
inputContainerStyle: ViewPropTypes.style,
inputStyle: Text.propTypes.style,
onClear: PropTypes.func,
onCancel: PropTypes.func,
Expand Down
10 changes: 4 additions & 6 deletions src/searchbar/SearchBar-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ class Search extends Component {
...attributes
} = this.props;

const {
style: loadingStyle,
...otherLoadingProps
} = loadingProps;
const { style: loadingStyle, ...otherLoadingProps } = loadingProps;

let Icon = MaterialIcons;
if (icon.type) {
Expand Down Expand Up @@ -96,8 +93,9 @@ class Search extends Component {
round && { borderRadius: Platform.OS === 'ios' ? 15 : 20 },
inputStyle && inputStyle,
clearIcon && showLoading && { paddingRight: 50 },
((clearIcon && !showLoading) ||
(!clearIcon && showLoading)) && { paddingRight: 30 },
((clearIcon && !showLoading) || (!clearIcon && showLoading)) && {
paddingRight: 30,
},
]}
/>
{!noIcon && (
Expand Down
6 changes: 4 additions & 2 deletions src/searchbar/SearchBar-ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SearchBar extends Component {
leftIcon,
leftIconContainerStyle,
rightIconContainerStyle,
inputContainerStyle,
inputStyle,
noIcon,
placeholderTextColor,
Expand All @@ -84,7 +85,7 @@ class SearchBar extends Component {
<Ionicon size={20} name={'ios-search'} color={IOS_GRAY} />
);
return (
<View style={styles.container}>
<View style={[styles.container, containerStyle]}>
<Input
{...attributes}
onFocus={this.onFocus}
Expand All @@ -95,7 +96,7 @@ class SearchBar extends Component {
containerStyle={[
styles.inputContainer,
!hasFocus && { width: SCREEN_WIDTH - 32, marginRight: 15 },
containerStyle,
inputContainerStyle,
]}
leftIcon={noIcon ? undefined : leftIcon ? leftIcon : searchIcon}
leftIconContainerStyle={[
Expand Down Expand Up @@ -148,6 +149,7 @@ SearchBar.propTypes = {
leftIcon: PropTypes.object,
leftIconContainerStyle: ViewPropTypes.style,
rightIconContainerStyle: ViewPropTypes.style,
inputContainerStyle: ViewPropTypes.style,
inputStyle: Text.propTypes.style,
placeholderTextColor: PropTypes.string,
};
Expand Down
26 changes: 10 additions & 16 deletions src/searchbar/__tests__/SearchBar-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,37 @@ describe('Android SearchBar component', () => {
});

it('should render without search icon', () => {
const component = shallow(
<SearchBar noIcon />
);
const component = shallow(<SearchBar noIcon />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});

it('should render without clear icon', () => {
const component = shallow(
<SearchBar clearIcon={false} />
);
const component = shallow(<SearchBar clearIcon={false} />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});

it('should call onFocus when input is focused', () => {
const onFocusMock = jest.fn();
const component = shallow(
<SearchBar onFocus={onFocusMock} />
);
const component = shallow(<SearchBar onFocus={onFocusMock} />);
component.find('Input').simulate('focus');
expect(onFocusMock).toBeCalled();
});

it('should call onBlur when input is blured', () => {
const onBlurMock = jest.fn();
const component = shallow(
<SearchBar onFocus={onBlurMock} />
);
const component = shallow(<SearchBar onFocus={onBlurMock} />);
component.find('Input').simulate('focus');
component.find('Input').simulate('blur');
expect(onBlurMock).toBeCalled();
});

it('should call onChangeText when input is changed', () => {
const onChangeMock = jest.fn();
const component = shallow(
<SearchBar onChangeText={onChangeMock} />
);
const component = shallow(<SearchBar onChangeText={onChangeMock} />);
component.find('Input').simulate('changeText', 'test');
expect(onChangeMock).toBeCalled();
});
Expand All @@ -75,7 +65,11 @@ describe('Android SearchBar component', () => {
const onClearMock = jest.fn();
const onCancelMock = jest.fn();
const component = shallow(
<SearchBar onChangeText={onChangeTextMock} onClear={onClearMock} onCancel={onCancelMock} />
<SearchBar
onChangeText={onChangeTextMock}
onClear={onClearMock}
onCancel={onCancelMock}
/>
);

expect(component.length).toBe(1);
Expand Down
34 changes: 12 additions & 22 deletions src/searchbar/__tests__/SearchBar-ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,65 +28,51 @@ describe('iOS SearchBar component', () => {
});

it('should render with a custom search icon', () => {
const component = shallow(
<SearchBar leftIcon={<View />} />
);
const component = shallow(<SearchBar leftIcon={<View />} />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});

it('should render without search icon', () => {
const component = shallow(
<SearchBar noIcon />
);
const component = shallow(<SearchBar noIcon />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});

it('should render without clear icon', () => {
const component = shallow(
<SearchBar clearIcon={false} />
);
const component = shallow(<SearchBar clearIcon={false} />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});

it('should render with a custom Cancel button title', () => {
const component = shallow(
<SearchBar cancelButtonTitle="Annuler" />
);
const component = shallow(<SearchBar cancelButtonTitle="Annuler" />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});

it('should call onFocus when input is focused', () => {
const onFocusMock = jest.fn();
const component = shallow(
<SearchBar onFocus={onFocusMock} />
);
const component = shallow(<SearchBar onFocus={onFocusMock} />);
component.find('Input').simulate('focus');
expect(onFocusMock).toBeCalled();
});

it('should call onBlur when input is blured', () => {
const onBlurMock = jest.fn();
const component = shallow(
<SearchBar onFocus={onBlurMock} />
);
const component = shallow(<SearchBar onFocus={onBlurMock} />);
component.find('Input').simulate('focus');
component.find('Input').simulate('blur');
expect(onBlurMock).toBeCalled();
});

it('should call onChangeText when input is changed', () => {
const onChangeMock = jest.fn();
const component = shallow(
<SearchBar onChangeText={onChangeMock} />
);
const component = shallow(<SearchBar onChangeText={onChangeMock} />);
component.find('Input').simulate('changeText', 'test');
expect(onChangeMock).toBeCalled();
});
Expand All @@ -96,7 +82,11 @@ describe('iOS SearchBar component', () => {
const onClearMock = jest.fn();
const onCancelMock = jest.fn();
const component = shallow(
<SearchBar onChangeText={onChangeTextMock} onClear={onClearMock} onCancel={onCancelMock} />
<SearchBar
onChangeText={onChangeTextMock}
onClear={onClearMock}
onCancel={onCancelMock}
/>
);

expect(component.length).toBe(1);
Expand Down
18 changes: 3 additions & 15 deletions src/searchbar/__tests__/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,21 @@ describe('SearchBar wrapper component', () => {
});

it('should render a default SearchBar if wrong platform', () => {
const component = shallow(
<SearchBar
platform="wrong-platform"
/>
);
const component = shallow(<SearchBar platform="wrong-platform" />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});

it('should render an iOS SearchBar', () => {
const component = shallow(
<SearchBar
platform="ios"
/>
);
const component = shallow(<SearchBar platform="ios" />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});

it('should render an Android SearchBar', () => {
const component = shallow(
<SearchBar
platform="android"
/>
);
const component = shallow(<SearchBar platform="android" />);

expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
Expand Down
75 changes: 45 additions & 30 deletions src/searchbar/__tests__/__snapshots__/SearchBar-android.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
exports[`Android SearchBar component should render with a custom methods 1`] = `
<View
style={
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
}
Array [
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
},
undefined,
]
}
>
<Input
Expand Down Expand Up @@ -77,12 +80,15 @@ exports[`Android SearchBar component should render with a custom methods 1`] = `
exports[`Android SearchBar component should render with loading 1`] = `
<View
style={
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
}
Array [
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
},
undefined,
]
}
>
<Input
Expand Down Expand Up @@ -166,12 +172,15 @@ exports[`Android SearchBar component should render with loading 1`] = `
exports[`Android SearchBar component should render without clear icon 1`] = `
<View
style={
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
}
Array [
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
},
undefined,
]
}
>
<Input
Expand Down Expand Up @@ -240,12 +249,15 @@ exports[`Android SearchBar component should render without clear icon 1`] = `
exports[`Android SearchBar component should render without issues 1`] = `
<View
style={
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
}
Array [
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
},
undefined,
]
}
>
<Input
Expand Down Expand Up @@ -314,12 +326,15 @@ exports[`Android SearchBar component should render without issues 1`] = `
exports[`Android SearchBar component should render without search icon 1`] = `
<View
style={
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
}
Array [
Object {
"backgroundColor": "white",
"paddingBottom": 8,
"paddingTop": 8,
"width": 750,
},
undefined,
]
}
>
<Input
Expand Down

0 comments on commit fdfaa09

Please sign in to comment.