Skip to content

Commit

Permalink
fix: optimize scroll position observer after video fullscreen exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-romaniuk committed Apr 25, 2024
1 parent fbb3ed5 commit f818307
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/courseware/course/sequence/Unit/hooks/useIFrameBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ const useIFrameBehavior = ({
if (type === messageTypes.resize) {
setIframeHeight(payload.height);

// We observe exit from the video xblock fullscreen mode
// and scroll to the previously saved scroll position
if (windowTopOffset !== null) {
window.scrollTo(0, Number(windowTopOffset));
}

if (!hasLoaded && iframeHeight === 0 && payload.height > 0) {
setHasLoaded(true);
if (onLoaded) {
onLoaded();
}
}
} else if (type === messageTypes.videoFullScreen) {
// We observe exit from the video xblock fullscreen mode
// and scroll to the previously saved scroll position
if (!payload.open && windowTopOffset !== null) {
window.scrollTo(0, Number(windowTopOffset));
}

// We listen for this message from LMS to know when we need to
// save or reset scroll position on toggle video xblock fullscreen mode
setWindowTopOffset(payload.open ? window.scrollY : null);
Expand Down

0 comments on commit f818307

Please sign in to comment.