question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Agenda: allow to scroll past the initial selected day?

See original GitHub issue

Hi,

Thanks for this great project

Let’s take the example agenda that is published on expo

The initial day is selected={'2017-05-16'}

The loading function is:

  loadItems(day) {
    setTimeout(() => {
      for (let i = -15; i < 85; i++) {
        const time = day.timestamp + i * 24 * 60 * 60 * 1000;
        // load items for that time
        // ...
      }
    }

To my understanding, the purpose of this function is to load new items data as the user is changing date or scrolling. It is also triggered initially on initial day.

In this demo, we can see the purpose of loading next 85 days, and previous 15 days.

Yet, even if 15 days before the initial day selected={'2017-05-16'} have been loaded in state, the UI does not allow to scroll back in time. The only way to browse items of a past day is to open the knob and select a date. In my app I don’t want the knob so it means there’s no easy way to access the past items.

I don’t know what could be a good solution to this problem. I guess rendering items lazily at the top after mount would mess-up with scroll position. For me a good enough solution would be that every items provided on mount could be rendered initially, and for otherwise keep current behavior.

What do you think?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:52
  • Comments:38 (7 by maintainers)

github_iconTop GitHub Comments

15reactions
saigyouyoucommented, Mar 12, 2019

@slorber

I have a simple way to solve it, though not perfect. Add a _onRefresh func in react-native-calendars/src/agenda/reservation-list/index.js

_onRefresh = () => {
  let h = 0;
  let scrollPosition = 0;
  const selectedDay = this.props.selectedDay.clone();
  const iterator = parseDate(this.props.selectedDay.clone().getTime()-3600*24*10*1000);
  let reservations = [];
  for (let i = 0; i < 10; i++) {
    const res = this.getReservationsForDay(iterator, this.props);
    if (res) {
      reservations = reservations.concat(res);
    }
    iterator.addDays(1);
  }
  scrollPosition = reservations.length;
  for (let i = 10; i < 30; i++) {
    const res = this.getReservationsForDay(iterator, this.props);
    if (res) {
      reservations = reservations.concat(res);
    }
    iterator.addDays(1);
  }
  this.setState({
    reservations
  }, () => {
    setTimeout(() => {
      let h = 0;
      for (let i = 0; i < scrollPosition; i++) {
        h += this.heights[i] || 0;
      }
      this.list.scrollToOffset({offset: h, animated: false});
      this.props.onDayChange(selectedDay, false);
    }, 100);
  });
}

And rewite the onRefresh in render()

<FlatList
  ...
  onRefresh={this._onRefresh}

then add a parmas in onDaychange func in react-native-calendars/src/agenda/index.js

onDayChange(day, f=true) {
  ...
  this.calendar.scrollToDay(day, this.calendarOffset(), withAnimation && f); //add f here
 ...

It works in the demo. If you want to use in your project, maybe you need change some parmas to fit your project.

14reactions
chapeljuicecommented, Nov 7, 2017

Personally I don’t think infinite past scrolling is even needed.

If we could at least set a currentDate, then set pastScrollRange to any number, I would expect the calendar open up to the currentDate, but be able to scroll to x months previously until you get back to the pastScrollRange value.

Does that make sense? Is this a different request, or similar enough?

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - Agenda - dynamically change selected day
I'm using the agenda. Also, I want to change the selected day when the user clicks on some button in that screen. My...
Read more >
Show Schedule from certain time but still be able to scroll?
Is it possible to have the schedule view default to showing that start time, but still allow scrolling up to earlier times?
Read more >
Agenda Commands (The Org Manual)
11.5 Commands in the Agenda Buffer. Entries in the agenda buffer are linked back to the Org file or diary file where they...
Read more >
12 Google Calendar Tricks You're Probably Not Using | PCMag
Click Settings and sharing, then choose Event notifications to customize the default notification settings for every event on that calendar. On ...
Read more >
Create, modify, or delete a meeting request or appointment in ...
You can add holidays and birthdays to your default calendar, or you can use separate ... solve your problem, scroll down to Still...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found