Skip to content

Commit a6805ae

Browse files
committed
fix(EAV-555): make prompter scroll
it was broken by introduction of `motion` in Sofie-Automation#1400
1 parent 32e12f6 commit a6805ae

File tree

1 file changed

+16
-74
lines changed

1 file changed

+16
-74
lines changed

packages/webui/src/client/ui/Prompter/PrompterView.tsx

Lines changed: 16 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -319,65 +319,28 @@ export class PrompterViewContent extends React.Component<Translated<IProps & ITr
319319
const target = document.querySelector<HTMLElement>(`[data-part-instance-id="${partInstanceId}"]`)
320320

321321
if (!target) return
322-
// Velocity(document.body, 'finish')
323-
// Velocity(target, 'scroll', { offset: -1 * scrollMargin, duration: 400, easing: 'ease-out' })
324-
const offsetTop = window.scrollY + target.offsetTop
325-
this._lastAnimation?.stop()
326-
this._lastAnimation = animate(
327-
window,
328-
{
329-
scrollY: offsetTop + -1 * scrollMargin,
330-
},
331-
{
332-
duration: 0.4,
333-
ease: 'easeOut',
334-
}
335-
)
322+
323+
const targetOffsetTop = target.getBoundingClientRect().top + window.pageYOffset
324+
this.animateScrollTo(targetOffsetTop - scrollMargin)
336325
}
337326
scrollToLive(): void {
338327
const scrollMargin = this.calculateScrollPosition()
339328
const current =
340329
document.querySelector<HTMLElement>('.prompter .live') || document.querySelector<HTMLElement>('.prompter .next')
341330

342331
if (!current) return
343-
// Velocity(document.body, 'finish')
344-
// Velocity(current, 'scroll', { offset: -1 * scrollMargin, duration: 400, easing: 'ease-out' })
345-
// }
346332

347-
const offsetTop = window.scrollY + current.offsetTop
348-
this._lastAnimation?.stop()
349-
this._lastAnimation = animate(
350-
window,
351-
{
352-
scrollY: offsetTop + -1 * scrollMargin,
353-
},
354-
{
355-
duration: 0.4,
356-
ease: 'easeOut',
357-
}
358-
)
333+
const targetOffsetTop = current.getBoundingClientRect().top + window.pageYOffset
334+
this.animateScrollTo(targetOffsetTop - scrollMargin)
359335
}
360336
scrollToNext(): void {
361337
const scrollMargin = this.calculateScrollPosition()
362338
const next = document.querySelector<HTMLElement>('.prompter .next')
363339

364340
if (!next) return
365-
// Velocity(document.body, 'finish')
366-
// Velocity(next, 'scroll', { offset: -1 * scrollMargin, duration: 400, easing: 'ease-out' })
367-
// }
368341

369-
const offsetTop = window.scrollY + next.offsetTop
370-
this._lastAnimation?.stop()
371-
this._lastAnimation = animate(
372-
window,
373-
{
374-
scrollY: offsetTop + -1 * scrollMargin,
375-
},
376-
{
377-
duration: 0.4,
378-
ease: 'easeOut',
379-
}
380-
)
342+
const targetOffsetTop = next.getBoundingClientRect().top + window.pageYOffset
343+
this.animateScrollTo(targetOffsetTop - scrollMargin)
381344
}
382345
scrollToPrevious(): void {
383346
const scrollMargin = this.calculateScrollPosition()
@@ -386,25 +349,8 @@ export class PrompterViewContent extends React.Component<Translated<IProps & ITr
386349
const target = anchors[anchors.length - 2] || anchors[0]
387350
if (!target) return
388351

389-
// Velocity(document.body, 'finish')
390-
// Velocity(document.body, 'scroll', {
391-
// offset: window.scrollY - scrollMargin + target[0],
392-
// duration: 200,
393-
// easing: 'ease-out',
394-
// })
395-
396-
const offsetTop = window.scrollY + target[0]
397-
this._lastAnimation?.stop()
398-
this._lastAnimation = animate(
399-
window,
400-
{
401-
scrollY: offsetTop + -1 * scrollMargin,
402-
},
403-
{
404-
duration: 0.4,
405-
ease: 'easeOut',
406-
}
407-
)
352+
const targetOffsetTop = target[0] + window.pageYOffset
353+
this.animateScrollTo(targetOffsetTop - scrollMargin)
408354
}
409355
scrollToFollowing(): void {
410356
const scrollMargin = this.calculateScrollPosition()
@@ -413,22 +359,18 @@ export class PrompterViewContent extends React.Component<Translated<IProps & ITr
413359
const target = anchors[0]
414360
if (!target) return
415361

416-
// Velocity(document.body, 'finish')
417-
// Velocity(document.body, 'scroll', {
418-
// offset: window.scrollY - scrollMargin + target[0],
419-
// duration: 200,
420-
// easing: 'ease-out',
421-
// })
422-
const offsetTop = window.scrollY + target[0]
362+
const targetOffsetTop = target[0] + window.pageYOffset
363+
this.animateScrollTo(targetOffsetTop - scrollMargin)
364+
}
365+
private animateScrollTo(scrollToPosition: number) {
423366
this._lastAnimation?.stop()
424367
this._lastAnimation = animate(
425-
window,
426-
{
427-
scrollY: offsetTop + -1 * scrollMargin,
428-
},
368+
window.scrollY,
369+
scrollToPosition,
429370
{
430371
duration: 0.4,
431372
ease: 'easeOut',
373+
onUpdate: (latest) => window.scrollTo(0, latest),
432374
}
433375
)
434376
}

0 commit comments

Comments
 (0)