I'm working on developing event planner using react-native-calendars
and there is one thing in the Agenda
that I do not understand. How does this function work? I guess it goes through every day in the calendar and assigns random events to them, but how exactly is it performed? Where is the function responsible for displaying dots below the dates in the calendar? Is there a way I can modify this function and use it to adding custom events to the Agenda? Here is loadItems
code:
loadItems(day) {
setTimeout(() => {
for (let i = -15; i < 85; i++) {
const time = day.timestamp + i * 24 * 60 * 60 * 1000;
const strTime = this.timeToString(time);
if (!this.state.items[strTime]) {
this.state.items[strTime] = [];
const numItems = Math.floor(Math.random() * 3 + 1);
for (let j = 0; j < numItems; j++) {
this.state.items[strTime].push({
name: 'Item for ' + strTime + ' #' + j,
height: Math.max(50, Math.floor(Math.random() * 150))
});
}
}
}
const newItems = {};
Object.keys(this.state.items).forEach(key => {
newItems[key] = this.state.items[key];
});
this.setState({
items: newItems
});
}, 1000);
}
And here is a photo of how the Agenda screen actually looks like:
question from:
https://stackoverflow.com/questions/65924827/loaditems-function-in-react-native-calendars-how-does-it-work 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…