Git Product home page Git Product logo

Comments (11)

maggialejandro avatar maggialejandro commented on July 28, 2024

thank you, it's fixed on v3.4.1

from react-native-calendario.

anija avatar anija commented on July 28, 2024

I hope this will be released as soon as possible, since 3.5.0 is broken and I have to dig into closed issue to find this.

from react-native-calendario.

vargajacint avatar vargajacint commented on July 28, 2024

@anija I think it's already released

from react-native-calendario.

anija avatar anija commented on July 28, 2024

I've tried with v3.4.1 and v3.5.0, both on react-native-months v1.6.3, and I still got the issue. When I select a date in a month and then select another date in another month, the values are not correct, like "onPress" function is wrongly memoized.

from react-native-calendario.

vargajacint avatar vargajacint commented on July 28, 2024

Here is my yarn.lock

react-native-calendario@^3.4.1:
  version "3.4.1"
  resolved "https://registry.yarnpkg.com/react-native-calendario/-/react-native-calendario-3.4.1.tgz#0520d0061ffe12ab0bb824cc7d1b9b844509d213"
  integrity sha512-KdhxgO+HRATf6KHGUExwvv4jaohpkj2vCjNUTacCln2QWwKw4E+ZdVYutEnaWbwP/f+VwiBcsxTPSgnyla4Kpw==
  dependencies:
    moment "2.29.1"
    react-native-month "^1.6.2"
    

And here is my application that using the feature:
Simulator Screenshot - iPhone 15 Pro - 2023-10-30 at 18 44 45

Could you share your code?

from react-native-calendario.

anija avatar anija commented on July 28, 2024

You can succesfully select a startDate in one month and the endDate in the month after?

from react-native-calendario.

vargajacint avatar vargajacint commented on July 28, 2024

@anija Yep!

from react-native-calendario.

mtsymlov avatar mtsymlov commented on July 28, 2024

Uploading Simulator Screen Recording - iPhone 14 Pro Max - 2023-12-12 at 15.03.44.mp4…

@maggialejandro This week I've caught the same problem on 3.5.0. It looks as the handler for onPress caches a previous state for months which were not rendered in the first render.

I used the fix which set a pressed value to a separate useState and additional useEffect watched for changes.

from react-native-calendario.

maggialejandro avatar maggialejandro commented on July 28, 2024

Uploading Simulator Screen Recording - iPhone 14 Pro Max - 2023-12-12 at 15.03.44.mp4…

@maggialejandro This week I've caught the same problem on 3.5.0. It looks as the handler for onPress caches a previous state for months which were not rendered in the first render.

I used the fix which set a pressed value to a separate useState and additional useEffect watched for changes.

Hi @mtsymlov, the video didn't finish uploading. What props are you using in the Calendar?

from react-native-calendario.

mtsymlov avatar mtsymlov commented on July 28, 2024

@maggialejandro

I've uploaded video to Google Drive.

import React, { useEffect, useState } from 'react'
import { StyleProp, StyleSheet, ViewStyle } from 'react-native'
import Presentation from 'presentation'
import Utils from 'utils'

import { Calendar } from 'react-native-calendario'
import { Box } from 'presentation/components/atoms'
import { Button } from 'presentation/components/moleculas'

const THEME = {
  monthTitleTextStyle: {
    color: Presentation.Theme.colors['text-secondary'],
    fontWeight: '400',
    fontSize: 18,
  },
  emptyMonthContainerStyle: {},
  emptyMonthTextStyle: {
    fontWeight: '400',
  },
  weekColumnsContainerStyle: {},
  weekColumnStyle: {
    paddingVertical: 10,
  },
  weekColumnTextStyle: {
    color: Presentation.Theme.colors['text-secondary-light'],
    fontSize: 13,
  },
  nonTouchableDayContainerStyle: {},
  nonTouchableDayTextStyle: {
    color: 'white',
  },
  startDateContainerStyle: {
    backgroundColor: Presentation.Theme.colors['background-primary'],
  },
  endDateContainerStyle: {
    backgroundColor: Presentation.Theme.colors['background-primary'],
  },
  dayContainerStyle: {},
  dayTextStyle: {
    color: Presentation.Theme.colors['text-basic'],
    fontWeight: '300',
    fontSize: 16,
  },
  dayOutOfRangeContainerStyle: {},
  dayOutOfRangeTextStyle: {},
  todayContainerStyle: {
    backgroundColor: Presentation.Theme.colors['background-secondary'],
    borderRadius: 1000,
  },
  todayTextStyle: {
    color: Presentation.Theme.colors['text-basic'],
  },
  activeDayContainerStyle: {
    // backgroundColor: Presentation.Theme.colors['background-secondary-light'],
    backgroundColor: '#f2f9c8',
  },
  activeDayTextStyle: {
    color: Presentation.Theme.colors['text-basic'],
  },
  nonTouchableLastMonthDayTextStyle: {},
} as const

const MONTH_HEIGHT = 370 // there was found in the library constants

type CalendarDate = Datestamp | undefined

interface Props {
  contentContainerStyles?: StyleProp<ViewStyle>
  onChange: (startDate: CalendarDate, endDate: CalendarDate) => void
  initialStartDate: CalendarDate
  initialEndDate: CalendarDate
}

const FullScreenCalendar: React.FC<Props> = (props) => {
  const { contentContainerStyles, initialStartDate, initialEndDate, onChange } = props

  const [startDate, setStartDate] = useState<CalendarDate>(initialStartDate)
  const [endDate, setEndDate] = useState<CalendarDate>(initialEndDate)
  const [pressedDate, setPressedDate] = useState<Date | undefined>()

  useEffect(() => {
    if (pressedDate) {
      const datestamp = Utils.Date.toDatestampFromDate(pressedDate)

      if (startDate && endDate) {
        if (startDate === endDate && startDate === datestamp) {
          setStartDate(undefined)
          setEndDate(undefined)
          onChange(undefined, undefined)
        } else {
          setStartDate(datestamp)
          setEndDate(undefined)
          onChange(datestamp, undefined)
        }
      } else if (startDate && !endDate) {
        if (startDate > datestamp) {
          setEndDate(startDate)
          setStartDate(datestamp)
          onChange(datestamp, startDate)
        } else if (startDate === datestamp) {
          setStartDate(undefined)
          onChange(undefined, endDate)
        } else {
          setEndDate(datestamp)
          onChange(startDate, datestamp)
        }
      } else if (!startDate && !endDate) {
        setStartDate(datestamp)
        onChange(datestamp, endDate)
      }

      setPressedDate(undefined)
    }
  }, [endDate, onChange, pressedDate, startDate])

  const containerStyles = React.useMemo(
    () => [contentContainerStyles, styles.ContentContainer],
    [contentContainerStyles],
  )

  return (
    <Box>
      {(startDate || endDate) && (
        <Box position={'absolute'} bottom={120} right={20} zIndex={1000}>
          <Button
            color={'basic'}
            fullWidth={true}
            icon={'restore'}
            onPress={() => {
              setStartDate(undefined)
              setEndDate(undefined)
              onChange(undefined, undefined)
            }}
            size={'small'}
            title={'Reset'}
          />
        </Box>
      )}
      <Calendar
        disableOffsetDays={true}
        monthHeight={MONTH_HEIGHT}
        firstDayMonday={true}
        startingMonth={'2023-01-01'}
        numberOfMonths={100}
        showsVerticalScrollIndicator={false}
        onPress={setPressedDate}
        startDate={startDate ? new Date(`${startDate}`) : undefined}
        endDate={endDate ? new Date(`${endDate}`) : undefined}
        contentContainerStyle={containerStyles}
        theme={THEME}
      />
    </Box>
  )
}

const styles = StyleSheet.create({
  ContentContainer: {
    paddingTop: 100,
    paddingBottom: 200,
    paddingHorizontal: Presentation.Theme.screenPadding / 2,
  },
})

export default FullScreenCalendar

from react-native-calendario.

mtsymlov avatar mtsymlov commented on July 28, 2024

@maggialejandro my calendar has 12 months, start_date and end_date is today i.e. December is shown below by default. If I select period from June to December it works okay. But if I select period in January it doesn't work properly.

In onPress handler I see that January contains start_date and end_date from first render, even I changed start_date and end_date 5 times before.

Please feel free to ask me more about environment or something else.

from react-native-calendario.

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.