Skip to content

Commit

Permalink
scrollToTime method honors a whole duration, not just a time. closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Aug 7, 2019
1 parent 973f28f commit 0f11db3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
next
----

- scrollToTime method honors a whole duration, not just a time (#4935)
- some background events wouldn't recieve eventClick or hovering (#3148, #4750)
- fix infinite recursion when custom view type is itself (#4198)
- respect firstDay setting when weekNumberCalculation set to ISO (#4734)
Expand Down
2 changes: 1 addition & 1 deletion packages-premium
6 changes: 3 additions & 3 deletions packages/core/src/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,10 +1280,10 @@ export default class Calendar {
// -----------------------------------------------------------------------------------------------------------------

scrollToTime(timeInput: DurationInput) {
let time = createDuration(timeInput)
let duration = createDuration(timeInput)

if (time) {
this.component.view.scrollToTime(time)
if (duration) {
this.component.view.scrollToDuration(duration)
}
}

Expand Down
18 changes: 8 additions & 10 deletions packages/core/src/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default abstract class View extends DateComponent<ViewProps> {
renderDatesWrap(dateProfile: DateProfile) {
this.renderDates(dateProfile)
this.addScroll({
timeMs: createDuration(this.opt('scrollTime')).milliseconds
duration: createDuration(this.opt('scrollTime'))
})
this.startNowIndicator(dateProfile) // shouldn't render yet because updateSize will be called soon
}
Expand Down Expand Up @@ -405,13 +405,13 @@ export default abstract class View extends DateComponent<ViewProps> {


applyScroll(scroll, isResize: boolean) {
let { timeMs } = scroll
let { duration } = scroll

if (timeMs != null) {
delete scroll.timeMs
if (duration != null) {
delete scroll.duration

if (this.props.dateProfile) { // dates rendered yet?
__assign(scroll, this.computeDateScroll(timeMs))
__assign(scroll, this.computeDateScroll(duration))
}
}

Expand All @@ -421,7 +421,7 @@ export default abstract class View extends DateComponent<ViewProps> {
}


computeDateScroll(timeMs: number) {
computeDateScroll(duration: Duration) {
return {} // subclasses must implement
}

Expand All @@ -437,10 +437,8 @@ export default abstract class View extends DateComponent<ViewProps> {


// for API
scrollToTime(time: Duration) {
this.applyScroll({
timeMs: time.milliseconds
}, false)
scrollToDuration(duration: Duration) {
this.applyScroll({ duration }, false)
}

}
Expand Down
5 changes: 3 additions & 2 deletions packages/daygrid/src/AbstractDayGridView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
buildGotoAnchorHtml,
ComponentContext,
ViewSpec,
DateProfileGenerator
DateProfileGenerator,
Duration
} from '@fullcalendar/core'
import DayGridDateProfileGenerator from './DayGridDateProfileGenerator'
import DayGrid from './DayGrid'
Expand Down Expand Up @@ -243,7 +244,7 @@ export default abstract class DayGridView extends View {
------------------------------------------------------------------------------------------------------------------*/


computeDateScroll(timeMs: number) {
computeDateScroll(duration: Duration) {
return { top: 0 }
}

Expand Down
6 changes: 3 additions & 3 deletions packages/timegrid/src/AbstractTimeGridView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
View, ViewSpec, DateProfileGenerator,
ComponentContext,
createFormatter, diffDays,
buildGotoAnchorHtml, getAllDayHtml
buildGotoAnchorHtml, getAllDayHtml, Duration
} from '@fullcalendar/core'
import { DayGrid } from '@fullcalendar/daygrid'
import TimeGrid from './TimeGrid'
Expand Down Expand Up @@ -248,8 +248,8 @@ export default abstract class TimeGridView extends View {


// Computes the initial pre-configured scroll state prior to allowing the user to change it
computeDateScroll(timeMs: number) {
let top = this.timeGrid.computeTimeTop(timeMs)
computeDateScroll(duration: Duration) {
let top = this.timeGrid.computeTimeTop(duration)

// zoom can give weird floating-point values. rather scroll a little bit further
top = Math.ceil(top)
Expand Down
6 changes: 3 additions & 3 deletions packages/timegrid/src/TimeGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,15 @@ export default class TimeGrid extends DateComponent<TimeGridProps> {
if (!startOfDayDate) {
startOfDayDate = startOfDay(when)
}
return this.computeTimeTop(when.valueOf() - startOfDayDate.valueOf())
return this.computeTimeTop(createDuration(when.valueOf() - startOfDayDate.valueOf()))
}


// Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration).
computeTimeTop(timeMs: number) {
computeTimeTop(duration: Duration) {
let len = this.slatEls.length
let dateProfile = this.props.dateProfile
let slatCoverage = (timeMs - asRoughMs(dateProfile.minTime)) / asRoughMs(this.slotDuration) // floating-point value of # of slots covered
let slatCoverage = (duration.milliseconds - asRoughMs(dateProfile.minTime)) / asRoughMs(this.slotDuration) // floating-point value of # of slots covered
let slatIndex
let slatRemainder

Expand Down

0 comments on commit 0f11db3

Please sign in to comment.