Coder Social home page Coder Social logo

Comments (12)

turkle12 avatar turkle12 commented on May 5, 2024 2

@chapeljuice this is a basic version of what I used.

<Calendar firstDay={1} onDayPress={this.onSelectDay} markedDates={this.dates} markingType="interactive" minDate={today} hideExtraDays={true} />

This is the onSelectDay function

`const { booked, dates } = this.state
const selectedDate = date.dateString

  if ( dates[selectedDate] ) {
    const newDates = { ...dates }
    delete newDates[selectedDate]
    this.setState( {
      dates: newDates
    } )

  } else {
    const newDates = { ...dates }
    newDates[selectedDate] = [
      {startingDay: true, color: colors.sea, textColor: colors.white},
      {endingDay: true, color: colors.sea, textColor: colors.white},
    ]
    this.setState( {
      dates: newDates
    }  )
  }`

from react-native-calendars.

tautvilas avatar tautvilas commented on May 5, 2024 1

It should be working, I suspect there is a bug in componentShouldUpdate and rerender does not happen. I will look into it.

from react-native-calendars.

davidfloegel avatar davidfloegel commented on May 5, 2024 1

Yes dude that's perfect now!! cheers mate :)

from react-native-calendars.

turkle12 avatar turkle12 commented on May 5, 2024 1

Sorry to bring this up but I'm trying to implement this functionality but I'm a bit stumped as to how. Could either of you @tautvilas @davidfloegel help out?
Thanks

(Let me know if this needs to be a separate issue)

from react-native-calendars.

davidfloegel avatar davidfloegel commented on May 5, 2024

Awesome thank you :)

from react-native-calendars.

tautvilas avatar tautvilas commented on May 5, 2024

Do you mutate this.state.marked in onDayPress ? I think the API is built on the premise that immutable objects are being passed to it (so that reference checks can be done in shouldComponentUpdate). What if you recreate the this.state.marked object on each selection? Maybe it solves the problem?

from react-native-calendars.

davidfloegel avatar davidfloegel commented on May 5, 2024

from react-native-calendars.

tautvilas avatar tautvilas commented on May 5, 2024

could you post onSelect code?

from react-native-calendars.

davidfloegel avatar davidfloegel commented on May 5, 2024

Sorry for the delay!

Sorry for the messy code, it's just for trying out:

onSelect( date ) {
        const { marked } = this.state

        let { year, month, day } = date
        month = month < 10 ? `0${ month }` : month
        day = day < 10 ? `0${ day }` : day
        const key = `${ year }-${ month }-${ day }`


        const index = marked.indexOf( key )

        if( index > -1 ) {
            this.setState( { marked: [
                ...marked.slice( 0, index ),
                ...marked.slice( index + 1 )
            ] } )
        } else {
            this.setState( { marked: [
                ...marked,
                key
            ] } )
        }
    }

I even tried to do a deep clone when passing in the dates into the calendar but no luck!

from react-native-calendars.

tautvilas avatar tautvilas commented on May 5, 2024

Hey, I changed marking api in new version to be easier to use. Now you can specified if date is selected or marked in same markedDates object

https://github.com/wix/react-native-calendars/blob/master/README.md#date-marking

Also added dateString prop to object returned from onDayPress so you don't need to do manual conversion anymore.

Plz check if these changes solve your bug

from react-native-calendars.

chapeljuice avatar chapeljuice commented on May 5, 2024

I would also like to know how to do this if you have a minute to spare for some code examples! Lovely calendar, btw!

from react-native-calendars.

Veeraharikumar avatar Veeraharikumar commented on May 5, 2024

Hi @tautvilas ,
im trying to highlight days for whole years.But i can only highlight days for current month.How to highlight days for all months using onMonthChange().

from react-native-calendars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.