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

Fix: limit resize observer to width #3467

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
10 changes: 9 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Renderer extends EventEmitter<RendererEvents> {
private isScrollable = false
private audioData: AudioBuffer | null = null
private resizeObserver: ResizeObserver | null = null
private lastContainerWidth = 0
private isDragging = false

constructor(options: WaveSurferOptions, audioElement?: HTMLElement) {
Expand Down Expand Up @@ -103,11 +104,18 @@ class Renderer extends EventEmitter<RendererEvents> {
// Re-render the waveform on container resize
const delay = this.createDelay(100)
this.resizeObserver = new ResizeObserver(() => {
delay(() => this.reRender())
delay(() => this.onContainerResize())
})
this.resizeObserver.observe(this.scrollContainer)
}

private onContainerResize() {
const width = this.parent.clientWidth
if (width === this.lastContainerWidth && this.options.height !== 'auto') return
this.lastContainerWidth = width
this.reRender()
}

private initDrag() {
makeDraggable(
this.wrapper,
Expand Down