React-native-calendars: Changing state on onVisibleMonthChange in CalendarList

Created on 19 Jul 2019  路  8Comments  路  Source: wix/react-native-calendars

I had an issue that when I used setState on onVisibleMonthsChange the previous and future months would get invisible and only showed the month name and the year.

To fix this problem I added this on index.js of CalendarList:

On contructor:
this.scrollTimeout = undefined;

On onViewableItemsChanged:
Before:

if (this.props.onVisibleMonthsChange) {
      this.props.onVisibleMonthsChange(visibleMonths);
}

After:

if (this.props.onVisibleMonthsChange) {
      clearTimeout(this.scrollTimeout);
      this.scrollTimeout = setTimeout(() => {
          this.props.onVisibleMonthsChange(visibleMonths);
      }, 200);
}

I hope this help anyone with the same problem

stale

Most helpful comment

No need to change the package source code, simply do this

InteractionManager.runAfterInteractions(() => {
    this.setState()
})

All 8 comments

Thank you! This solve my problem.

Thanks!!!

No need to change the package source code, simply do this

InteractionManager.runAfterInteractions(() => {
    this.setState()
})

No need to change the package source code, simply do this

InteractionManager.runAfterInteractions(() => {
    this.setState()
})

Thanks @sebzinck it works for me
onVisibleMonthsChange={this.onMonthChange}
....
onMonthChange = data => { InteractionManager.runAfterInteractions(() => { this.setState({ isLoading: true, planList: [], markerList: {}, // Your state }); }); };

I also have this problem I tried to use InteractionManager.runAfterInteractions but is it not working for me :(

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

It would be great if this was included in the example code or be fixed in the source.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ercpereda picture ercpereda  路  4Comments

nickitatkach picture nickitatkach  路  4Comments

chapeljuice picture chapeljuice  路  3Comments

microwin168 picture microwin168  路  4Comments

anishtr4 picture anishtr4  路  3Comments