@@ -93,6 +93,7 @@ const Unit = ({
93
93
const [ showError , setShowError ] = useState ( false ) ;
94
94
const [ modalOptions , setModalOptions ] = useState ( { open : false } ) ;
95
95
const [ shouldDisplayHonorCode , setShouldDisplayHonorCode ] = useState ( false ) ;
96
+ const [ windowTopOffset , setWindowTopOffset ] = useState ( null ) ;
96
97
97
98
const unit = useModel ( 'units' , id ) ;
98
99
const course = useModel ( 'coursewareMeta' , courseId ) ;
@@ -120,6 +121,13 @@ const Unit = ({
120
121
} = data ;
121
122
if ( type === 'plugin.resize' ) {
122
123
setIframeHeight ( payload . height ) ;
124
+
125
+ // We observe exit from the video xblock full screen mode
126
+ // and do page scroll to the previously saved scroll position
127
+ if ( windowTopOffset !== null ) {
128
+ window . scrollTo ( 0 , Number ( windowTopOffset ) ) ;
129
+ }
130
+
123
131
if ( ! hasLoaded && iframeHeight === 0 && payload . height > 0 ) {
124
132
setHasLoaded ( true ) ;
125
133
if ( onLoaded ) {
@@ -129,12 +137,16 @@ const Unit = ({
129
137
} else if ( type === 'plugin.modal' ) {
130
138
payload . open = true ;
131
139
setModalOptions ( payload ) ;
140
+ } else if ( type === 'plugin.videoFullScreen' ) {
141
+ // We listen for this message from LMS to know when we need to
142
+ // save or reset scroll position on toggle video xblock full screen mode.
143
+ setWindowTopOffset ( payload . open ? window . scrollY : null ) ;
132
144
} else if ( data . offset ) {
133
145
// We listen for this message from LMS to know when the page needs to
134
146
// be scrolled to another location on the page.
135
147
window . scrollTo ( 0 , data . offset + document . getElementById ( 'unit-iframe' ) . offsetTop ) ;
136
148
}
137
- } , [ id , setIframeHeight , hasLoaded , iframeHeight , setHasLoaded , onLoaded ] ) ;
149
+ } , [ id , setIframeHeight , hasLoaded , iframeHeight , setHasLoaded , onLoaded , setWindowTopOffset , windowTopOffset ] ) ;
138
150
useEventListener ( 'message' , receiveMessage ) ;
139
151
useEffect ( ( ) => {
140
152
sendUrlHashToFrame ( document . getElementById ( 'unit-iframe' ) ) ;
0 commit comments