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

Add scrollTimeTo() method #205

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ To use the component methods save a reference to it:
* **`goToDate(date, animated = true)`**: the component navigates to a custom date. Note: if the target date has not been rendered before, there may be a delay on the animation. See [this issue](https://github.com/hoangnm/react-native-week-view/issues/54) for details.
* **`goToNextPage(animated = true)`**: the component navigates to the next page (to the future). Note: if `prependMostRecent` is `true`, and the component is near the last page rendered, there may be a delay on the animation.
* **`goToPrevPage(animated = true)`**: the component navigates to the previous page (to the past). Note: if `prependMostRecent` is `false` (the default), and the component is near the first page rendered, there may be a delay on the animation.
* **`scrollToTime(minutes, options = { animated = false })`**: scroll vertically to a time in the day, provided in minutes. For example, to scroll to 13:00 hrs: `ref.scrollToTime(13 * 60)`.


### Custom `EventComponent`
Expand Down
15 changes: 12 additions & 3 deletions src/WeekView/WeekView.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,20 @@ export default class WeekView extends Component {
calculateTimes = memoizeOne(calculateTimesArray);

scrollToVerticalStart = () => {
this.scrollToTime(this.props.startHour * 60, { animated: false });
};

scrollToTime = (minutes, options = {}) => {
if (this.verticalAgenda) {
const { startHour, hoursInDisplay, beginAgendaAt } = this.props;
const startHeight = minutesToYDimension(hoursInDisplay, startHour * 60);
const { animated = false } = options || {};
const { hoursInDisplay, beginAgendaAt } = this.props;
const height = minutesToYDimension(hoursInDisplay, minutes);
const agendaOffset = minutesToYDimension(hoursInDisplay, beginAgendaAt);
this.verticalAgenda.scrollTo({ y: startHeight - agendaOffset, x: 0, animated: false });
this.verticalAgenda.scrollTo({
y: height - agendaOffset,
x: 0,
animated,
});
}
};

Expand Down