BugiDev / react-native-calendar-strip

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

TypeError: Cannot read property 'scrollToDate' #367

Closed strelov1 closed 1 year ago

strelov1 commented 1 year ago

When I try to select another date with the ref I have this error

TypeError: Cannot read property 'scrollToDate'

CleanShot 2023-05-04 at 10 48 21@2x

Here is my configuration

const calendarRef = useRef(null);
const nextDay = () => {
       if (calendarRef.current) {
            const addOneDay = new Date(currentDate);
            addOneDay.setDate(currentDate.getDate() + 1);
            calendarRef.current.setSelectedDate(addOneDay.toISOString())
        }
}

return (
<CalendarStrip
   ref={calendarRef}
   calendarAnimation={{type: 'sequence', duration: 30}}
   style={styles.calendarStrip}
   onDateSelected={onDateChange}
/>
)
tanyicheng commented 1 year ago

You need to add scrollable={true} to your code. like this <CalendarStrip ref={calendarRef} scrollable={true} calendarAnimation={{type: 'sequence', duration: 30}} style={styles.calendarStrip} onDateSelected={onDateChange} />

strelov1 commented 1 year ago

Thanks @tanyicheng. It's helped