BugiDev / react-native-calendar-strip

Easy to use and visually stunning calendar component for React Native.
MIT License
949 stars 327 forks source link

onWeekChanged skips some dates when use scrollerPaging #279

Closed psolom closed 3 years ago

psolom commented 3 years ago

Hey @peacechen, thanks for the great plugin.

I use scrollable + paging and I would like to get correct start and end moment dates. Seems that onWeekChanged fires only at specific conditions, for instance when you step into another week or month while scrolling without paging. But when one enables scrollerPaging it's reasonable he would expect the event fires on scroll stops (onMomentumScrollEnd).

If you try to rely on onWeekChanged to get start/end days it appears that it's unreliable way because onWeekChanged doesn't fire on each day. It took me a lot of time to understand that, because the whole thing looked like the callback function just skipping some days and the behavior is buggy in general.

My suggestion is to add onMomentumScrollEnd to the at Scroller.js and create another callback prop (onWeekScrolled e.g.) and fire it inside of onMomentumScrollEnd.

That is how it could be:

  <RecyclerListView
    ref={rlv => this.rlv = rlv}
    layoutProvider={this.state.layoutProvider}
    dataProvider={this.state.dataProvider}
    rowRenderer={this.rowRenderer}
    extendedState={this.props.renderDayParams}
    initialRenderIndex={this.props.initialRenderIndex}
    onVisibleIndicesChanged={this.onVisibleIndicesChanged}
    isHorizontal
    externalScrollView={this.props.externalScrollView}
    scrollViewProps={{
      showsHorizontalScrollIndicator: false,
      contentContainerStyle: { paddingRight: this.state.itemWidth / 2 },
      onMomentumScrollEnd: () => {
        const visStart = this.state.visibleStartDate && this.state.visibleStartDate.clone();
        const visEnd = this.state.visibleEndDate && this.state.visibleEndDate.clone();
        this.props.onWeekScrolled && this.props.onWeekScrolled(visStart, visEnd);
      },
      ...pagingProps
    }}
  />
peacechen commented 3 years ago

That would be a useful addition. Would you be able to submit a PR for this too? Please create a dedicated function for the onMomentumScrollEnd callback to make the JSX easier to read.

psolom commented 3 years ago

Done. It would be great if you make a new release after merge.

peacechen commented 3 years ago

This has been published in 2.2.0

The linter caught a bug which I fixed in a follow-on commit. visibleStartIndex and visibleEndIndex were not declared in onScrollBeginDrag. Does the pre-commit hook not run on your system? The post-install script may not run immediately after forking or cloning the repo.

psolom commented 3 years ago

My bad. I was out of my IDE at that moment so I made commits directly in GitHub UI. Not the most convenient way I must admit. Anyhow thank you for fixing it and the new release.