BugiDev / react-native-calendar-strip

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

Starting date changed when scrolling #266

Closed rjuevesano closed 3 years ago

rjuevesano commented 3 years ago

Hello. I really need your help. I’m trying to add scrolling but the starting date has changed. If using arrows, it works fine.

Here’s my code:


<CalendarStrip
            ref={calendarStripRef}
            scrollable
            scrollerPaging
            showMonth={false}
            styleWeekend={false}
            useIsoWeekday={false}
            startingDate={dates[0]}
            style={{ height: 100 }}
            selectedDate={new Date()}
            scrollToOnSetSelectedDate={false}
            dayComponent={dayComponent}
            iconContainer={{
              alignItems: 'center',
              justifyContent: 'center',
              width: 20,
            }}
            iconLeft='angle-left'
            iconRight='angle-right'
            onWeekChanged={onWeekChanged}
          />

https://user-images.githubusercontent.com/4033035/106474459-e8bb3680-64df-11eb-8022-b91ab686526e.MP4

rjuevesano commented 3 years ago

Closing this issue. Got it working!

Jeyoung-Park commented 3 years ago

I'm facing the similar issue.

I solved it by giving values to selectors like below. leftSelector={<View />} rightSelector={<View />} but I think it is not a perfect solutioin.

Can you tell me how you solved it?

rjuevesano commented 3 years ago

@Jeyoung-Park I'm using this configuration

<CalendarStrip
    scrollable={true}
    scrollerPaging={true}
    showMonth={true}
    styleWeekend={false}
    useIsoWeekday={true}
    startingDate={dates[0]}
    ...
/>

and created a patch to fixed it on my end image

peacechen commented 3 years ago

@rjuevesano Would you mind submitting a PR?

Your modification should be able to be simplified as such:

      if (useIsoWeekday) {
        // isoWeekday starts from Monday
        date = this.setLocale(_startingDate.clone().isoWeekday(i + 1));
      } else {
        date = this.setLocale(_startingDate.clone().add(i, "days"));
      }

Please validate that also works. Would prefer the simpler code in the PR.

Jeyoung-Park commented 3 years ago

@rjuevesano @peacechen in my case, both solution works. Thanks for your help!

peacechen commented 3 years ago

2.2.2 has been published with @rjuevesano 's fix