Skip to content

Commit cc2e67b

Browse files
marcormMarco Marinangeli
andauthored
Add "index" to renderRow function (#678)
Co-authored-by: Marco Marinangeli <[email protected]>
1 parent ca8e5b6 commit cc2e67b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

GooglePlacesAutocomplete.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ interface GooglePlacesAutocompleteProps {
412412
renderHeaderComponent?: () => JSX.Element | React.ComponentType<{}>;
413413
renderLeftButton?: () => JSX.Element | React.ComponentType<{}>;
414414
renderRightButton?: () => JSX.Element | React.ComponentType<{}>;
415-
renderRow?: (data: GooglePlaceData) => JSX.Element | React.ComponentType<{}>;
415+
renderRow?: (data: GooglePlaceData, index: number) => JSX.Element | React.ComponentType<{}>;
416416
// sets the request URL to something other than the google api. Helpful if you want web support or to use your own api.
417417
requestUrl?: RequestUrl;
418418
styles?: Partial<Styles> | Object;

GooglePlacesAutocomplete.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
546546
return <ActivityIndicator animating={true} size='small' />;
547547
};
548548

549-
const _renderRowData = (rowData) => {
549+
const _renderRowData = (rowData, index) => {
550550
if (props.renderRow) {
551-
return props.renderRow(rowData);
551+
return props.renderRow(rowData, index);
552552
}
553553

554554
return (
@@ -592,7 +592,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
592592
return null;
593593
};
594594

595-
const _renderRow = (rowData = {}) => {
595+
const _renderRow = (rowData = {}, index) => {
596596
return (
597597
<ScrollView
598598
contentContainerStyle={
@@ -619,7 +619,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
619619
]}
620620
>
621621
{_renderLoader(rowData)}
622-
{_renderRowData(rowData)}
622+
{_renderRowData(rowData, index)}
623623
</View>
624624
</TouchableHighlight>
625625
</ScrollView>
@@ -745,7 +745,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
745745
keyExtractor={keyGenerator}
746746
extraData={[dataSource, props]}
747747
ItemSeparatorComponent={_renderSeparator}
748-
renderItem={({ item }) => _renderRow(item)}
748+
renderItem={({ item, index }) => _renderRow(item, index)}
749749
ListEmptyComponent={
750750
stateText.length > props.minLength && props.listEmptyComponent
751751
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ _This list is a work in progress. PRs welcome!_
249249
| renderHeaderComponent | function | use the `ListHeaderComponent` from `FlatList` when showing autocomplete results | | |
250250
| renderLeftButton | function | add a component to the left side of the Text Input | | |
251251
| renderRightButton | function | add a component to the right side of the Text Input | | |
252-
| renderRow | function | custom component to render each result row (use this to show an icon beside each result) | | |
252+
| 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 | | |
253253
| requestUrl | object | used to set the request url for the library | | |
254254
| returnKeyType | string | the return key text https://reactnative.dev/docs/textinput#returnkeytype | 'search' | |
255255
| styles | object | See styles section below | | |

0 commit comments

Comments
 (0)