From a09fa311888db5735b2f62b2d112a07058e73ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Wed, 26 May 2021 20:31:36 +0200 Subject: [PATCH] fix: Force update captions when element resizes (#3426) --- lib/text/ui_text_displayer.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/text/ui_text_displayer.js b/lib/text/ui_text_displayer.js index 60b36ecbc8..cda645f159 100644 --- a/lib/text/ui_text_displayer.js +++ b/lib/text/ui_text_displayer.js @@ -82,6 +82,15 @@ shaka.text.UITextDisplayer = class { this.eventManager_.listen(document, 'fullscreenchange', () => { this.updateCaptions_(/* forceUpdate= */ true); }); + + /** @private {ResizeObserver} */ + this.resizeObserver_ = null; + if ('ResizeObserver' in window) { + this.resizeObserver_ = new ResizeObserver(() => { + this.updateCaptions_(/* forceUpdate= */ true); + }); + this.resizeObserver_.observe(this.textContainer_); + } } @@ -132,6 +141,11 @@ shaka.text.UITextDisplayer = class { this.eventManager_.release(); this.eventManager_ = null; } + + if (this.resizeObserver_) { + this.resizeObserver_.disconnect(); + this.resizeObserver_ = null; + } }