react-native-autocomplete-input
Advanced tools
Comparing version 5.0.2 to 5.1.0
23
index.js
@@ -6,6 +6,10 @@ import React from 'react'; | ||
export const AutocompleteInput = (props) => { | ||
function renderResultList(data, listProps) { | ||
const { style, ...flatListProps } = listProps; | ||
function renderResultList() { | ||
const { renderResultList: renderFunction, style } = props; | ||
const listProps = { | ||
style: [styles.list, style], | ||
...props, | ||
}; | ||
return <FlatList data={data} style={[styles.list, style]} {...flatListProps} />; | ||
return renderFunction(listProps); | ||
} | ||
@@ -31,2 +35,4 @@ | ||
onStartShouldSetResponderCapture, | ||
// flatListProps is only used in defaultResultList | ||
// eslint-disable-next-line no-unused-vars | ||
flatListProps, | ||
@@ -40,3 +46,3 @@ } = props; | ||
<View style={[styles.container, containerStyle]}> | ||
<View style={[styles.inputContainer, inputContainerStyle]}>{renderTextInput(props)}</View> | ||
<View style={[styles.inputContainer, inputContainerStyle]}>{renderTextInput()}</View> | ||
{!hideResults && ( | ||
@@ -47,3 +53,3 @@ <View | ||
> | ||
{showResults && renderResultList(data, flatListProps)} | ||
{showResults && renderResultList()} | ||
</View> | ||
@@ -98,2 +104,7 @@ )} | ||
renderTextInput: PropTypes.func, | ||
/** | ||
* renders custom result list. Can be used to replace FlatList. | ||
* All props passed to this function. | ||
*/ | ||
renderResultList: PropTypes.func, | ||
}; | ||
@@ -103,2 +114,3 @@ | ||
const defaultRenderItem = ({ item }) => <Text>{item}</Text>; | ||
const defaultResultList = ({ data, flatListProps }) => <FlatList data={data} {...flatListProps} />; | ||
@@ -109,2 +121,3 @@ AutocompleteInput.defaultProps = { | ||
renderTextInput: (props) => <TextInput {...props} />, | ||
renderResultList: defaultResultList, | ||
flatListProps: { | ||
@@ -111,0 +124,0 @@ renderItem: defaultRenderItem, |
{ | ||
"name": "react-native-autocomplete-input", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"description": "Pure javascript autocomplete input for react-native", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -97,5 +97,6 @@ # react-native-autocomplete-input | ||
| flatListProps | object | custom props to [FlatList](https://facebook.github.io/react-native/docs/flatlist.html). | | ||
| renderResultList | function | render custom result list. Can be used to replace FlatList. All props passed to this function. | | ||
## Known issues | ||
* By default the autocomplete will not behave as expected inside a `<ScrollView />`. Set the scroll view's prop to fix this: `keyboardShouldPersistTaps={true}` for RN <= 0.39, or `keyboardShouldPersistTaps='always'` for RN >= 0.40. ([#5](https://github.com/mrlaessig/react-native-autocomplete-input/issues/5)). | ||
* By default the autocomplete will not behave as expected inside a `<ScrollView />`. Set the scroll view's prop to fix this: `keyboardShouldPersistTaps={true}` for RN <= 0.39, or `keyboardShouldPersistTaps='always'` for RN >= 0.40. ([#5](https://github.com/mrlaessig/react-native-autocomplete-input/issues/5)). Alternatively, you can use renderResultList to render a custom result list that does not use FlatList. See the tests for an example. | ||
* If you want to test with Jest add ```jest.mock('react-native-autocomplete-input', () => 'Autocomplete');``` to your test. | ||
@@ -102,0 +103,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11202
166
105
4