Skip to content

Commit 96547bd

Browse files
author
maksymkordiyak
committed
2 parents be7018e + 8c56bf7 commit 96547bd

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Change valueExtractor and pass the data to Autocomplete without fetchDataUrl
132132
:----------------- |:--------------------------------------------- | --------:|:------------------
133133
autoCorrect | Disable auto-correct | Boolean | true
134134
highlightText | Highlight search results | Boolean | true
135+
highLightColor | Highlight text color | String | #129a8d
135136
rightContent | Render additional text to the right of the item | Boolean | false
136137
resetOnSelect | Reset the input after choosing an item | Boolean | false
137138
minimumCharactersCount | Perform API request after certain number of characters entered | Number | 2
@@ -155,15 +156,17 @@ Change valueExtractor and pass the data to Autocomplete without fetchDataUrl
155156
listHeaderTextStyle | Styles for list header text | Object | -
156157
overlayStyle | Styles for overlay view | Object | -
157158
pickerStyle | Styles for item picker view | Object | -
158-
containerStyle | Styles for dropdown container view | Object | -
159+
containerStyle | Styles for dropdown container view | Object | -
160+
scrollStyle | Styles for dropdown flatlist | Object | -
159161
scrollToInput | Focus on selected field | Function | -
160-
handleSelectItem | Selection callback (agrs: item, index) | Function | -
162+
handleSelectItem | Selection callback (args: item, index) | Function | -
161163
onDropdownShow | Show keyboard | Function | -
162-
onDropdownClose | Hide keyboard | Function | -
164+
onDropdownClose | Hide keyboard | Function | -
165+
onChangeText | Autocomplete input text changes | Function | -
163166
renderIcon | Render icon near input | Function | -
164167
valueExtractor | Extract value from item (args: item, index) | Function | ({ value }) => value
165168
rightTextExtractor | Extract value from item (args: item, index) | Function | ({ value }) => value
166-
fetchData | Fetch data for autocomplete | Function | (searchInput) => Promise
169+
fetchData | Fetch data for autocomplete | Function | -
167170

168171
### Authors:
169172

components/Autocomplete/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class Autocomplete extends Component {
2929
}
3030

3131
handleInputChange(text) {
32-
const {minimumCharactersCount, waitInterval} = this.props;
32+
const {onChangeText, minimumCharactersCount, waitInterval} = this.props;
33+
if (onChangeText) {
34+
onChangeText(text);
35+
}
3336
clearTimeout(this.timer);
3437
this.setState({inputValue: text});
3538
if (text.length > minimumCharactersCount) {
@@ -114,14 +117,14 @@ class Autocomplete extends Component {
114117
}
115118

116119
setItem(value) {
117-
const { index, handleSelectItem, valueExtractor, resetOnSelect } = this.props;
120+
const {index, handleSelectItem, valueExtractor, resetOnSelect} = this.props;
118121
handleSelectItem(value, index);
119-
122+
120123
if (resetOnSelect) {
121-
this.setState({ inputValue: '' });
124+
this.setState({inputValue: ""});
122125
} else {
123-
const capitalizedValue = capitalizeFirstLetter(valueExtractor(value));
124-
this.setState({inputValue: capitalizedValue});
126+
const capitalizedValue = capitalizeFirstLetter(valueExtractor(value));
127+
this.setState({inputValue: capitalizedValue});
125128
}
126129
}
127130

@@ -233,8 +236,8 @@ Autocomplete.propTypes = {
233236
renderIcon: func,
234237
scrollToInput: func.isRequired,
235238
handleSelectItem: func.isRequired,
236-
onDropdownClose: func.isRequired,
237-
onDropdownShow: func.isRequired,
239+
onDropdownClose: func,
240+
onDropdownShow: func,
238241
rightTextExtractor: func,
239242
fetchData: func,
240243
};

components/Dropdown/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ export default class Dropdown extends PureComponent {
454454
render() {
455455
const {
456456
containerStyle,
457+
scrollStyle,
457458
overlayStyle: overlayStyleOverrides,
458459
pickerStyle: pickerStyleOverrides,
459460
supportedOrientations,
@@ -497,7 +498,7 @@ export default class Dropdown extends PureComponent {
497498
keyboardShouldPersistTaps="always"
498499
ref={this.updateScrollRef}
499500
data={itemData}
500-
style={styles.scroll}
501+
style={[styles.scroll, scrollStyle]}
501502
renderItem={this.renderItem}
502503
keyExtractor={this.keyExtractor}
503504
scrollEnabled={visibleItemCount <= itemCount}

index.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ViewStyle, TextStyle, StyleProp } from 'react-native';
66
type AutocompleteProps = {
77
autoCorrect?: boolean,
88
highlightText?: boolean,
9+
highLightColor?: string,
910
rightContent?: boolean,
1011
resetOnSelect?: boolean,
1112
minimumCharactersCount?: number,
@@ -30,11 +31,13 @@ type AutocompleteProps = {
3031
overlayStyle?: StyleProp<TextStyle>;
3132
pickerStyle?: StyleProp<TextStyle>;
3233
containerStyle?: StyleProp<ViewStyle>;
34+
scrollStyle?: StyleProp<ViewStyle>;
3335

3436
scrollToInput: (ev: any) => void,
3537
handleSelectItem: (item: any, index: number) => void,
36-
onDropdownShow: () => void,
37-
onDropdownClose: () => void,
38+
onDropdownShow?: () => void,
39+
onDropdownClose?: () => void,
40+
onChangeText?: (search: string) => void,
3841
renderIcon?: () => void,
3942
valueExtractor?: (item: any) => void,
4043
rightTextExtractor?: (item: any) => void,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"dependencies": {
1616
"prop-types": "^15.6.2",
1717
"query-string": "^6.2.0",
18-
"react-native-keyboard-aware-scroll-view": "^0.7.4",
18+
"react-native-keyboard-aware-scroll-view": "^0.8.0",
1919
"react-native-material-buttons": "^0.5.0",
2020
"react-native-material-ripple": "^0.8.0"
2121
},

0 commit comments

Comments
 (0)