React-native-calendars: AgendaList: not scrolling to the initially selected date at component mount

Created on 17 Oct 2019  路  11Comments  路  Source: wix/react-native-calendars

Description

AgendaList component does not scroll to the initially selected date (date prop in the CalendarProvider) at component mount. Also reselecting that date in the calendar doesn't scroll, because the AgendaList doesn't detect a date change. Also if the selected day is today, there is no scroll to "Today" button, although the component does not display that date.

Expected Behavior

On component mount the AgendaList should display the date selected by the date prop in the CalendarProvider component.

Observed Behavior

AgendaList displays the first component from the sections prop array.

Environment

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

Also specify:

  1. Phone/emulator/simulator & version:
    XCode simulator, device: IPad Pro 9.7 inch

Reproducible Demo

  1. Clone wix repo.
  2. Change line 155 in "react-native-calendars/example/src/screens/expandableCalendar.js"
    from date={ITEMS[0].title} to date={ITEMS[3].title}
  3. Run the expandable calendar example
Bug report

Most helpful comment

have same problem

All 11 comments

have same problem

Hey, I'm facing the same issue. when I update the selected date (in my case it is Today) when my data updates than AgendaList doesn't scroll to that date. It always shows the first element in the data array.
Anyone who can help me in this issue,
Thanks. :)

Same problem here!

I am facing the same issue here.

Using react-native-calendars v1.282.0. Using Android.

The code bellow is executing:

componentDidMount() {
    const { date } = this.props.context;
    if (date !== this._topSection) {
      setTimeout(() => {
        const sectionIndex = this.getSectionIndex(date); // --> finding section 7 (correct)
        this.scrollToSection(sectionIndex);
      }, 500);
    }
  }
scrollToSection(sectionIndex) {
    if (this.list.current && sectionIndex !== undefined) {
      this.sectionScroll = true; // to avoid setDate() in onViewableItemsChanged
      this._topSection = this.props.sections[sectionIndex].title;

      this.list.current.scrollToLocation({
        animated: true,
        sectionIndex: sectionIndex,
        itemIndex: 0,
        viewPosition: 0, // position at the top
        viewOffset: commons.isAndroid ? this.sectionHeight : 0 // -> sectionHeight is undefined, maybe here is the bug
      });
    }
  }

Is it consistent? @JulioOrellana
Does increasing the time out are fixing the problem?

We need to think about a better solution.

Is it consistent? @JulioOrellana
Does increasing the time out are fixing the problem?

We need to think about a better solution.

Nope, it is not fixing it, but I am trying a few things

Please check that the date you are passing is correct and it his a section to scroll to.

Yes, dates are correct

agendaList dates:  
2019-11-05 <- top date
2020-06-05 <- prop date

But I seems to be working if timeout is greater tan 2 seconds, because if I use 2000 in timeout, it scrolls to index.

FlatList his a prop called onContentSizeChanged.
Can you try to use it? (Without timeout)

Hi,
Does there is a fix for this one ?
I am facing the same issue.

Thx

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sommeshEwall picture sommeshEwall  路  3Comments

dobiedad picture dobiedad  路  4Comments

nickitatkach picture nickitatkach  路  4Comments

matieux picture matieux  路  4Comments

henrikra picture henrikra  路  3Comments