Skip to content

Commit 5bb269f

Browse files
committed
fix: use throttle in onWheelScrollInner for more fluid scrolling
1 parent 26cc415 commit 5bb269f

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

packages/webui/src/client/ui/RundownView.tsx

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,24 +2152,36 @@ const RundownViewContent = translateWithTracker<IPropsWithReady, IState, ITracke
21522152
}
21532153
}
21542154

2155-
onWheelScrollInner = _.debounce(() => {
2156-
if (this.state.followLiveSegments && this.props.playlist && this.props.playlist.activationId) {
2157-
const liveSegmentComponent = document.querySelector('.segment-timeline.live')
2158-
if (liveSegmentComponent) {
2159-
const offsetPosition = liveSegmentComponent.getBoundingClientRect()
2160-
// if it's closer to the top edge than the headerHeight
2161-
const segmentComponentTooHigh = offsetPosition.top < getHeaderHeight()
2162-
// or if it's closer to the bottom edge than very close to the top
2163-
const segmentComponentTooLow =
2164-
offsetPosition.bottom < window.innerHeight - getHeaderHeight() - 20 - (offsetPosition.height * 3) / 2
2165-
if (segmentComponentTooHigh || segmentComponentTooLow) {
2166-
this.setState({
2167-
followLiveSegments: false,
2168-
})
2155+
onWheelScrollInner = _.throttle(
2156+
() => {
2157+
if (this.state.followLiveSegments && this.props.playlist && this.props.playlist.activationId) {
2158+
const liveSegmentComponent = document.querySelector('.segment-timeline.live')
2159+
if (liveSegmentComponent) {
2160+
const offsetPosition = liveSegmentComponent.getBoundingClientRect()
2161+
const headerHeight = getHeaderHeight()
2162+
2163+
// Use a buffer zone to prevent oscillation
2164+
const topBuffer = headerHeight + 10
2165+
const bottomBuffer = window.innerHeight - headerHeight - 20 - (offsetPosition.height * 3) / 2
2166+
2167+
// Check if segment is outside the comfortable viewing area
2168+
const segmentComponentTooHigh = offsetPosition.top < topBuffer
2169+
const segmentComponentTooLow = offsetPosition.bottom < bottomBuffer
2170+
2171+
if (segmentComponentTooHigh || segmentComponentTooLow) {
2172+
// Only change state if we need to
2173+
if (this.state.followLiveSegments) {
2174+
this.setState({
2175+
followLiveSegments: false,
2176+
})
2177+
}
2178+
}
21692179
}
21702180
}
2171-
}
2172-
}, 250)
2181+
},
2182+
100,
2183+
{ leading: true, trailing: true }
2184+
)
21732185

21742186
onWheel = (e: React.WheelEvent<HTMLDivElement>) => {
21752187
if (e.deltaX === 0 && e.deltaY !== 0 && !e.altKey && !e.shiftKey && !e.ctrlKey && !e.metaKey) {

0 commit comments

Comments
 (0)