Update popup position on scroll

This commit is contained in:
toasted-nutbread 2020-01-11 14:16:58 -05:00
parent e73e4c032c
commit 21dbb19565

View File

@ -46,6 +46,7 @@ class Frontend extends TextScanner {
const {zoomFactor} = await apiGetZoom(); const {zoomFactor} = await apiGetZoom();
this._pageZoomFactor = zoomFactor; this._pageZoomFactor = zoomFactor;
window.addEventListener('scroll', this.onScroll.bind(this), false);
window.addEventListener('resize', this.onResize.bind(this), false); window.addEventListener('resize', this.onResize.bind(this), false);
const visualViewport = window.visualViewport; const visualViewport = window.visualViewport;
@ -65,11 +66,12 @@ class Frontend extends TextScanner {
} }
} }
async onResize() { onResize() {
const textSource = this.getCurrentTextSource(); this._updatePopupPosition();
if (textSource !== null && await this.popup.isVisible()) {
this._showPopupContent(textSource);
} }
onScroll() {
this._updatePopupPosition();
} }
onWindowMessage(e) { onWindowMessage(e) {
@ -99,7 +101,7 @@ class Frontend extends TextScanner {
} }
onVisualViewportScroll() { onVisualViewportScroll() {
// TODO this._updatePopupPosition();
} }
onVisualViewportResize() { onVisualViewportResize() {
@ -224,7 +226,14 @@ class Frontend extends TextScanner {
this._contentScale = contentScale; this._contentScale = contentScale;
this.popup.setContentScale(this._contentScale); this.popup.setContentScale(this._contentScale);
this.onResize(); this._updatePopupPosition();
}
async _updatePopupPosition() {
const textSource = this.getCurrentTextSource();
if (textSource !== null && await this.popup.isVisible()) {
this._showPopupContent(textSource);
}
} }
static _getVisualViewportScale() { static _getVisualViewportScale() {