Skip to content

Commit e899265

Browse files
authored
Merge pull request #1795 from wix/fix/Agenda_keyExtractor
Agenda - fix keyExtractor for reservation list
2 parents 4024190 + f2d9a97 commit e899265

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

example/src/screens/agenda.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default class AgendaScreen extends Component<State> {
3737
// theme={{calendarBackground: 'red', agendaKnobColor: 'green'}}
3838
//renderDay={(day, item) => (<Text>{day ? day.day: 'item'}</Text>)}
3939
// hideExtraDays={false}
40+
// showOnlySelectedDayItems
4041
/>
4142
);
4243
}

src/agenda/reservation-list/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export type ReservationListProps = ReservationProps & {
4444
refreshing?: boolean;
4545
/** If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make sure to also set the refreshing prop correctly */
4646
onRefresh?: () => void;
47+
/** Extractor for underlying FlatList. Ensure that this is unique per item, or else scrolling may have duplicated and / or missing items. */
48+
keyExtractor?: (item: DayAgenda, index: number) => string;
4749
};
4850

4951
interface DayAgenda {
@@ -75,7 +77,8 @@ class ReservationList extends Component<ReservationListProps, State> {
7577
onMomentumScrollEnd: PropTypes.func,
7678
refreshControl: PropTypes.element,
7779
refreshing: PropTypes.bool,
78-
onRefresh: PropTypes.func
80+
onRefresh: PropTypes.func,
81+
keyExtractor: PropTypes.func
7982
};
8083

8184
static defaultProps = {
@@ -258,7 +261,9 @@ class ReservationList extends Component<ReservationListProps, State> {
258261
);
259262
};
260263

261-
keyExtractor = (_item: DayAgenda, index: number) => String(index);
264+
keyExtractor = (item: DayAgenda, index: number) => {
265+
return this.props.keyExtractor?.(item, index) || `${item?.reservation?.day}${index}`;
266+
}
262267

263268
render() {
264269
const {items, selectedDay, theme, style} = this.props;

0 commit comments

Comments
 (0)