React-native-calendars: Agenda loadItemsForMonth on scroll uses previous month

Created on 5 Nov 2018  路  6Comments  路  Source: wix/react-native-calendars

Description

When scrolling the main Agenda and CalendarList views, loadItemsForMonth seems to be using the previous month rather than the current month.

On initial load and on clicking into a date from CalendarList views, the month is correct. On scrolling to the next month in Agenda, it begins to use the previous month.

Expected Behavior

The correct month should be used for the scroll events.

Observed Behavior

On iOS, the initial load and clicking on a date in CalendarList work, while scrolling breaks the month.

On Android, the initial load seems to re-call loadItemsForMonth on a componentDidMount, triggering it twice with a second

Environment

Please run these commands in the project folder and fill in their results:

Also specify:

  1. Phone/emulator/simulator & version: iPhone X + iPhone X Simulator, 12.1 - Android Emulator Pixel

Reproducible Demo

nov-05-2018 15-41-07

nov-05-2018 15-45-49

Most helpful comment

So, I was facing a problem that is related. I use this to fetch more data of other months. What I discovered is that even when the agenda in the top is minified if I scroll the list, the loadItemsForMonth is triggered. So I verify in the loadItemsForMonth if the bar is maximized and only in this case I fetch more data.
For load more data when scrolling the list, I use the onDayChange.

<Agenda
  onCalendarToggled={flag => this.setState({ locked: flag })}
  items={items}
  onDayPress={this._dayChange}
  onDayChange={this._dayChange}
  loadItemsForMonth={(day) => {
    if (this.state.locked) {
      this._dayChange(day);
    }
  }}
  //ANOTHER PROPERTIES
/>
_dayChange = (day) => {
  const { year, month, dateString } = day;
     if (parseInt(moment(this.state.currentMonth, 'MMMM YYYY').format('MM'), 10) !== parseInt(month, 10)) {
        this.setState({ currentMonth: moment(dateString).format('MMMM YYYY') });
        //FETCH MORE DATA
     }
}

All 6 comments

I believe this is due to loadItemsForMonths being called by onVisibleMonthChange.

The 0th index is always taken which leads to it usually being the previous month. I'll submit a PR in a bit after some testing - I believe using the 1st index if it exists fixes this issue.

I'm facing some problems to render the list when I have many items, on your example the list scroll works correctly, can you post your code on codesandbox?

my problem:
https://user-images.githubusercontent.com/8001358/47867461-55ff2f00-dde0-11e8-8b17-056329aea983.gif

So, I was facing a problem that is related. I use this to fetch more data of other months. What I discovered is that even when the agenda in the top is minified if I scroll the list, the loadItemsForMonth is triggered. So I verify in the loadItemsForMonth if the bar is maximized and only in this case I fetch more data.
For load more data when scrolling the list, I use the onDayChange.

<Agenda
  onCalendarToggled={flag => this.setState({ locked: flag })}
  items={items}
  onDayPress={this._dayChange}
  onDayChange={this._dayChange}
  loadItemsForMonth={(day) => {
    if (this.state.locked) {
      this._dayChange(day);
    }
  }}
  //ANOTHER PROPERTIES
/>
_dayChange = (day) => {
  const { year, month, dateString } = day;
     if (parseInt(moment(this.state.currentMonth, 'MMMM YYYY').format('MM'), 10) !== parseInt(month, 10)) {
        this.setState({ currentMonth: moment(dateString).format('MMMM YYYY') });
        //FETCH MORE DATA
     }
}

I just sent a PR that help to solve this problem. #746

Do you still have a problem?

How do you manage to create this part?
I can't load my items that way, could someone help me or guide me?
Captura de pantalla 2020-08-05 a la(s) 11 48 47

Was this page helpful?
0 / 5 - 0 ratings

Related issues

srichallamalla935 picture srichallamalla935  路  4Comments

Yandamuri picture Yandamuri  路  4Comments

akhilsanker picture akhilsanker  路  4Comments

sonnguyenit picture sonnguyenit  路  3Comments

anishtr4 picture anishtr4  路  3Comments