BugiDev / react-native-calendar-strip

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

I chose a date next week, when reder () doesn't show the next week only the current week. #79

Closed NothingSerious closed 4 years ago

NothingSerious commented 6 years ago

I want to use the updateWeekView () but this method is undefined.How do I fix it

peacechen commented 6 years ago

27 may be helpful

peacechen commented 6 years ago

@NothingSerious Did you pass a reference prop to the CalendarStrip component? Post your code to help us diagnose your issue.

NothingSerious commented 6 years ago
       <CalendarStrip
            ref='CalendarStrip'
            calendarAnimation={{ type: 'parallel', duration: 30 }}
            daySelectionAnimation={{ type: 'border', duration: 200, borderWidth: 1, borderHighlightColor: commonStyles.primaryColor.color }}
            style={{ height: 70, paddingHorizontal: 4, paddingVertical: 8, backgroundColor: 'white' }}
            calendarHeaderStyle={{ color: 'white' }}
            calendarColor={'#7743CE'}
            dateNumberStyle={{ color: '#505050' }}
            dateNameStyle={{ color: '#797979' }}
            highlightDateNumberStyle={{ color: commonStyles.primaryColor.color }}
            highlightDateNameStyle={{ color: commonStyles.primaryColor.color }}
            disabledDateNameStyle={{ color: 'grey' }}
            disabledDateNumberStyle={{ color: 'grey' }}
            datesWhitelist={datesWhitelist}
            datesBlacklist={datesBlacklist}
            selectedDate={this.state.selectDateString}
            startingdate={this.state.selectDateString}
            leftSelector={<Icon size={15} color='#B4B4B4' name='arrow-left' type='simple-line-icon' />}
            rightSelector={<Icon size={15} color='#B4B4B4' name='arrow-right' type='simple-line-icon' />}
            locale={locale}
            onDateSelected={date => this.onDayPress(date.format('YYYY-MM-DD'))}
            showMonth={false}
            useIsoWeekday={false}
          />

Below is the method that is called after the date of selection.

async onDayPress (dateString) { this.setState({ selectDate: dateString, selectDateString: dateString, calendarStripVisible: true, calendarVisible: false, scheduleLoading: true }) let { client, departmentId, queryDoctorsByDate, selectDoctor, querySchedules } = this.props await queryDoctorsByDate(client, { departmentId: departmentId, date: dateString }) await this.isExistDepartment(this.props.searchDoctorsByDate, departmentId) if (!isEmptyObject(this.state.selectDoctors)) { selectDoctor({ doctorId: this.state.selectDoctors[0].id }) await querySchedules(client, { departmentId, doctorId: this.state.selectDoctors[0].id, beginDate: dateString, endDate: dateString }) } this.setState({ scheduleLoading: false }) }

In this method, just call this.setstate (), the CalendarStrip work well. But if you request network data and update redux, the CalendarStrip will not show the week of the selection date.

peacechen commented 6 years ago

Couple of observations: onDayPress returns a Promise. The code inside it is in a different context than the caller's. You should bind onDayPress to your component's root context.

You set selectDate state to a formatted string instead of keeping the original Moment object. It's usually better to retain the original Moment object, and only format it to a string when you need to display it (or if another function can only handle a string). selectDateString is redundant as well. Pass selectDate to CalendarStrip's selectedDate and startingDate props (you have a typo as startingdate), preferably as the original Moment object as stated above.

None of these are CalendarStrip bugs. I recommend you review your code and brush up on ES6 Promises which will help you better debug.

NothingSerious commented 6 years ago

Thank you very much. My problem is solved, my code is fine. I have read The CalendarStrip source code, I annotated this method, and The CalendarStrip also works well.

peacechen commented 6 years ago

If you found a bug, please create a PR. Or you can post the code snippet here and I'll make the edit.

Looking at componentWillReceiveProps, it looks like using Moment to compare datetimes may be better.

vishalchakbesh1 commented 6 years ago

I am also having the same issue how you were able to fix it can you please share some details. I am on v1.3.1 I've also tried this method

this.refs.calendar.updateWeekView(selectedDate,range.start) but it always throws an undefined function error.

Though one thing I've noticed is that week change issue occurs only when the datesWhitelist is set in the props once you comment this the code seems to work fine.

Please suggest some solution.

peacechen commented 6 years ago

The datesWhiteList prop should not cause the updateWeekView method to be undefined. Please post your code and more details. Most likely your callback context is different than your component's context.

EgorZotov commented 5 years ago

Hi! I got the same propblem too. The source of the problem is updating weekData only if selectedDate changed in componentDidUpdate. This is quick fix.

151

peacechen commented 4 years ago

The updateWeekView method has been restored in 2.0.0.

Pirsanth commented 4 years ago

I still get the problem that updateWeekView is undefined (not a function)

peacechen commented 4 years ago

Which version of RNCS do you have installed in your project? The function is in the root class: https://github.com/BugiDev/react-native-calendar-strip/blob/master/src/CalendarStrip.js#L268