diff --git a/README.md b/README.md index 14a2cf99..064ad45f 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/WeekView/WeekView.js b/src/WeekView/WeekView.js index c18d9f0d..590ba0dc 100644 --- a/src/WeekView/WeekView.js +++ b/src/WeekView/WeekView.js @@ -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, + }); } };