react-native-calendars icon indicating copy to clipboard operation
react-native-calendars copied to clipboard

Now indicator appears ahead of time when TimelineProps start is not 0

Open DSimao94 opened this issue 2 years ago • 14 comments

I'm trying to get the Timeline to show only from 8h to 18h. Changing the TimelineProps start variable to 8 causes the now indicator to show 8 hours ahead of time.

image

It is now 1h:27m and the indicator shows 9h:27m

image

Resetting it to 0 makes it behave normally. Using v1.1297.0.

DSimao94 avatar May 20 '23 00:05 DSimao94

I did a bit of digging and it seems that the now indicator offset doesn't take into account the start prop, so its position will always be incorrect when the start is not 0. I was able to fix this with the following code.

  1. Inject start prop in the NowIndicator component {indexOfToday !== -1 && showNowIndicator && <NowIndicator startOffset={props.start} width={width / numberOfDays} left={left} styles={styles.current}/>} File - /src/timeline/Timeline.js Line 89

  2. Receive the new prop in the component const { styles, width, left, startOffset } = props; File - /src/timeline/NowIndicator.js Line 6

  3. Calculate the correct offset if(startOffset){ indicatorPosition = calcTimeOffset(HOUR_BLOCK_HEIGHT) - calcTimeOffset(HOUR_BLOCK_HEIGHT, startOffset) + calcTimeOffset(HOUR_BLOCK_HEIGHT, 0, new Date().getMinutes()); } File - /src/timeline/NowIndicator.js Line 8

DSimao94 avatar Jun 02 '23 22:06 DSimao94

@DSimao94 did you raise a PR for this fix?

jackfraser70 avatar Jul 14 '23 11:07 jackfraser70

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 15 '23 08:10 stale[bot]

Any fixes for this bug?

maxsl89 avatar Oct 24 '23 10:10 maxsl89

We are having the exact same issue!

It seems a PR has been submitted that fixes this issue: #2401 Can someone from @wix @contributors please have a look and review.

jerone avatar May 30 '24 11:05 jerone

I had to manually apply the change and patch it until the fix is merged, but thanks for calling out the fix @jerone šŸ‘

mr-ryan-james avatar Aug 05 '24 11:08 mr-ryan-james

Hello,

I’m working with the TimelineList component and encountered an issue when using the start and end properties in timelineProps.

When I set startHour and endHour to visually trim the calendar (e.g., from 8:00 AM to 8:00 PM), the logic for handling time selection breaks. Specifically, when a user tries to create an appointment by selecting a time(using onBackgroundLongPress), the returned time is shifted several hours earlier than expected. It seems like the start and end settings are impacting the underlying time logic of the TimelineList, which causes a mismatch in the actual time versus what is displayed. In the screenshots bellow you can see I select an empty cell with start time 12:00 and the calendar returns 05:00. Screenshot 2024-09-16 163500 Screenshot 2024-09-16 163529

Interestingly, when the start and end properties are not set, everything works perfectly — the time from the selected cell matches the expected time when creating appointments, but there are a lot of unnecessary visible hours I want gone. However, when I limit the visible hours, the logic for determining the correct time from a cell breaks.

The ideal solution would be to maintain the ability to trim the visible hours while ensuring that the time selection logic still works as expected. Has anyone experienced this issue or found a workaround?

Fragments of my code : <TimelineList timelineProps={{ start: 8, end: 20, unavailableHoursColor: "rgb(235, 235, 235)", onBackgroundLongPress: handleBackgroundLongPress, unavailableHours: unavailableHours, onEventPress(event) { openEventModal(event); }, renderEvent: renderEvent, theme: customTheme, }} events={events} showNowIndicator scrollToFirst = {true} initialTime={INITIAL_TIME} />

          -------------------------------------------------------------------------
          
          const handleBackgroundLongPress = useCallback(
    (timeString: string | null) => {
        if (!timeString) {
            console.error("Received null or undefined timeString:", timeString);
            return;
        } 
        const selectedTime = DateTime.fromFormat(timeString, "yyyy-MM-dd HH:mm:ss", { zone: 'utc' });

        if (!selectedTime.isValid) {
            console.error(`Invalid DateTime after parsing: the input "${timeString}" can't be parsed as ISO 8601`);
        } else {
            setNewAppointment((prev) => ({
                ...prev,
                start: selectedTime.toISO(), 
            }));

            setDisplayedDate(selectedTime.toFormat("dd MMMM, HH:mm"));
            openModal();
        }
    },
    [openModal]
);

Thank you in advance!

Viktor123vasilev avatar Sep 16 '24 13:09 Viktor123vasilev

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 22 '25 00:01 stale[bot]

Issue still relevant! And attached PR still the solution!

jerone avatar Jan 22 '25 01:01 jerone

Any news ?

loiclouvet avatar Feb 28 '25 17:02 loiclouvet

Also onBackgroundLongPress timeString value is affected by the same issue.

jerone avatar Apr 08 '25 12:04 jerone

+1

jball-117 avatar Jun 10 '25 13:06 jball-117

+1

AjleyArroyo avatar Sep 12 '25 02:09 AjleyArroyo