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

Add "index" to renderRow function #678

Merged
merged 1 commit into from
Jan 25, 2021
Merged
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
2 changes: 1 addition & 1 deletion GooglePlacesAutocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ interface GooglePlacesAutocompleteProps {
renderHeaderComponent?: () => JSX.Element | React.ComponentType<{}>;
renderLeftButton?: () => JSX.Element | React.ComponentType<{}>;
renderRightButton?: () => JSX.Element | React.ComponentType<{}>;
renderRow?: (data: GooglePlaceData) => JSX.Element | React.ComponentType<{}>;
renderRow?: (data: GooglePlaceData, index: number) => JSX.Element | React.ComponentType<{}>;
// sets the request URL to something other than the google api. Helpful if you want web support or to use your own api.
requestUrl?: RequestUrl;
styles?: Partial<Styles> | Object;
Expand Down
10 changes: 5 additions & 5 deletions GooglePlacesAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
return <ActivityIndicator animating={true} size='small' />;
};

const _renderRowData = (rowData) => {
const _renderRowData = (rowData, index) => {
if (props.renderRow) {
return props.renderRow(rowData);
return props.renderRow(rowData, index);
}

return (
Expand Down Expand Up @@ -592,7 +592,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
return null;
};

const _renderRow = (rowData = {}) => {
const _renderRow = (rowData = {}, index) => {
return (
<ScrollView
contentContainerStyle={
Expand All @@ -619,7 +619,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
]}
>
{_renderLoader(rowData)}
{_renderRowData(rowData)}
{_renderRowData(rowData, index)}
</View>
</TouchableHighlight>
</ScrollView>
Expand Down Expand Up @@ -745,7 +745,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
keyExtractor={keyGenerator}
extraData={[dataSource, props]}
ItemSeparatorComponent={_renderSeparator}
renderItem={({ item }) => _renderRow(item)}
renderItem={({ item, index }) => _renderRow(item, index)}
ListEmptyComponent={
stateText.length > props.minLength && props.listEmptyComponent
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ _This list is a work in progress. PRs welcome!_
| renderHeaderComponent | function | use the `ListHeaderComponent` from `FlatList` when showing autocomplete results | | |
| renderLeftButton | function | add a component to the left side of the Text Input | | |
| renderRightButton | function | add a component to the right side of the Text Input | | |
| renderRow | function | custom component to render each result row (use this to show an icon beside each result) | | |
| renderRow | function | custom component to render each result row (use this to show an icon beside each result). *data* and *index* will be passed as input parameters | | |
| requestUrl | object | used to set the request url for the library | | |
| returnKeyType | string | the return key text https://reactnative.dev/docs/textinput#returnkeytype | 'search' | |
| styles | object | See styles section below | | |
Expand Down