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

Feature: allow scrolling 1 day at the time #266

Merged
merged 12 commits into from
Oct 7, 2022

Conversation

pdpino
Copy link
Collaborator

@pdpino pdpino commented Sep 14, 2022

PR overview - Change logic to allow scrolling one day at the time. This fixes multiple issues:

  • Fixes Select number of days scrolled #128:
    • use prop allowScrollByOneDay={true} to scroll by days instead of by pages
  • Fixes wrong date with fixedHorizontally #141 (see this comment)
    • Adds the prop pageStartAt, that allows customizing the date shown in the left
    • Breaking change: prop weekStartsOn is removed. Instead, use prop pageStartAt.weekday (README has new prop details)
  • Fixes Selected Date Position. #185:
    • add left option to goToDate(date, { left: number }) --> the date will show at number of days from the left. i.e. Use left = 0 to show the target date at the most left
    • Breaking change: second parameter is no longer animated, now is an object { animated = true, left = null } (README has signature details)
  • Fixes goToNextDay & goToPreviousDay #186:
    • add goToNextDay() and goToPrevDay() methods
  • Fixes BUG: UI Drag #258:
    • I confirm this bug does not occur, users need to set allowScrollByOneDay={true} and it should work
    • (Though the issue may still occur in v0.16.0)

@pdpino pdpino added the type: feature enhancements or new features label Sep 14, 2022
@pdpino
Copy link
Collaborator Author

pdpino commented Sep 14, 2022

Small code walkthrough - (in case is useful for reviewing the PR 🙂)

  • the relevant state for horizontal pages scrolling is:
    • this.state.initialDates
    • this.currentPageIndex
    • dayOffset --> this one is new, useful to scroll by less than 1-page at the time
    • this.state.currentMoment (always derivated from the above ones)
  • Note: dayOffset is not persisted (is re-computed from currentMoment if necessary)
  • Code changes to support day offset:
    • onMomentumScrollEnd callback only minor changes
    • goToDate(date) computes target page-index and target day-offset (handles user options, offset overflow)
    • goToPageIndex() supports navigating to a page-index and day-offset
      • also needs to support old behavior with dayOffset = null | undefined
      • index and offset are handled via FlatList.scrollToIndex({ index, viewOffset, ... })

Copy link
Owner

@hoangnm hoangnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great

@hoangnm hoangnm merged commit fbe4f4a into hoangnm:master Oct 7, 2022
@rdewolff
Copy link

rdewolff commented Oct 7, 2022

Amazing! Thanks for your hard work 🥳

@rdewolff
Copy link

rdewolff commented Oct 7, 2022

Does the main README require some update?
We should show off all the new features in there too :)

@pdpino pdpino deleted the feature/shift-by-1-day branch October 12, 2022 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature enhancements or new features
Projects
None yet
4 participants