rghorbani / react-native-general-calendars

React Native Calendar Components 📆
MIT License
94 stars 16 forks source link

Issue with re-render #19

Closed brlocky closed 5 years ago

brlocky commented 5 years ago

After onDayPress and changing component state, the calendar list does not re-render.

Video example https://monosnap.com/file/XIqCU55VnNFNtsqnsf5hs5WZ9J52EY

I try'ed in several ways to paste the code in a way that you could see, but looks like github WYSYWYG is not prepared to accept code 🌊

`

onDayPress(date) { console.log('Selected day : ') console.log(date) const selectedDate = date.dateString

    let marked = true
    if (this.state.markedDates[selectedDate]) {
        // Already in marked dates, so reverse current marked state
        marked = !this.state.markedDates[selectedDate].selected
    }

    // Create a new object using object property spread since it should be immutable
    // Reading: https://davidwalsh.name/merge-objects
    const updatedMarkedDates = { ...this.state.markedDates, ...{ [selectedDate]: { 'selected': marked } } }

    this.setState({
        selectedDate: selectedDate,
        markedDates: updatedMarkedDates,
    })
}`
rghorbani commented 5 years ago

Hi, Is your problem fixed or it's still happening?

brlocky commented 5 years ago

Hi, Is your problem fixed or it's still happening?

Hi, the problem is solved. It was an issue with a function binding

brlocky commented 5 years ago

Hi,

Actually is a bit buggy still, in 2 weeks we will need to refactor our calendar.

try to enforce on the constructor function binding.

this.myFunction = this.myFunction.bind(this)

at the time that was the fix

Joe Attard-Owen notifications@github.com escreveu no dia quarta, 23/01/2019 à(s) 23:27:

Could you explain your issue/fix @brlocky https://github.com/brlocky? Having a similar issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rghorbani/react-native-general-calendars/issues/19#issuecomment-457006781, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4ZqLs3L2ZglYcd3MsLo1TtCClvQwPoks5vGO_vgaJpZM4YrmRe .

Joeao commented 5 years ago

I didn't realise that this plug-in was a fork of https://github.com/wix/react-native-calendars, so I switched to that and the problem was solved.