Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Items not showing in proper timeline #21

Open
vijay-fs opened this issue Feb 29, 2024 · 1 comment
Open

Items not showing in proper timeline #21

vijay-fs opened this issue Feb 29, 2024 · 1 comment

Comments

@vijay-fs
Copy link

import React, { useState, useMemo } from "react";
import { View,Text, ScrollView } from "react-native";
import moment from "moment";
import Timetable from "react-native-calendar-timetable";
import Calendar from "./Calendar";

const TimetableScreen = () => {
const [selectedDate, setSelectedDate] = useState(null);
const [date] = React.useState(new Date());
const [from] = React.useState(moment().subtract(3, "days").toDate());
const [till] = React.useState(moment().add(3, "days").toISOString());
const range = { from, till };
console.log(
{
Date1: moment().toDate(),
Date2: moment().add(2, "hours").toDate(),
},
"selectedDate"
);

const [items] = React.useState([
{
title: "Some event",
startDate: moment()
.set({ hour: 14, minute: 0, second: 0, millisecond: 0 })
.toDate(),
endDate: moment()
.set({ hour: 16, minute: 0, second: 0, millisecond: 0 })
.toDate(),
},
]);

function MyItemCard({ style, item, dayIndex, daysTotal }) {
console.log(item, dayIndex, daysTotal, "MyItemCard");
return (
<View
style={{
backgroundColor: "red",
borderRadius: 10,
elevation: 5,
}}
>
{item.title}
Start: {moment(item.startDate).format("YYYY-MM-DD HH:mm")}
End: {moment(item.endDate).format("YYYY-MM-DD HH:mm")}

);
}

const TimeTable = useMemo(() => {
  return (
    <Timetable
      items={items}
      renderItem={(props) => <MyItemCard {...props} />}
      date={selectedDate}
    />
  );
}, [selectedDate]);

return (
<View style={{ height: "60%", width: "90%", alignSelf: "center" }}>


{TimeTable}


);
};

export default TimetableScreen;

Timeline

@dorkyboi
Copy link
Owner

From your code, I can see that you are not applying the generated styles:

//                      ↓ - this property is unused
function MyItemCard({ style, item, dayIndex, daysTotal }) {
    console.log(item, dayIndex, daysTotal, "MyItemCard");
    return (
        <View
            style={{
                backgroundColor: "red",
                borderRadius: 10,
                elevation: 5,
                ...style, // ← use it here
            }}
        >
            {item.title}
            Start: {moment(item.startDate).format("YYYY-MM-DD HH:mm")}
            End: {moment(item.endDate).format("YYYY-MM-DD HH:mm")}
        </View>
    );
}

As per documentation, you should apply the given styles to your components. Also, be extra careful to not accidentally override any style property (unless that's what you want to do).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants