mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-30 22:59:35 +02:00
Fix:Epub rendition resize on screen orientation change #1213
This commit is contained in:
parent
b7e6cbf1ab
commit
494ff38ef3
1 changed files with 47 additions and 11 deletions
|
@ -34,6 +34,7 @@ export default {
|
||||||
currentLocationNum: 0,
|
currentLocationNum: 0,
|
||||||
currentLocationCfi: null,
|
currentLocationCfi: null,
|
||||||
inittingDisplay: true,
|
inittingDisplay: true,
|
||||||
|
isRefreshingUI: false,
|
||||||
ereaderSettings: {
|
ereaderSettings: {
|
||||||
theme: 'dark',
|
theme: 'dark',
|
||||||
fontScale: 100,
|
fontScale: 100,
|
||||||
|
@ -43,7 +44,7 @@ export default {
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
isPlayerOpen() {
|
isPlayerOpen() {
|
||||||
this.updateHeight()
|
this.refreshUI()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -135,11 +136,6 @@ export default {
|
||||||
goToChapter(href) {
|
goToChapter(href) {
|
||||||
return this.rendition?.display(href)
|
return this.rendition?.display(href)
|
||||||
},
|
},
|
||||||
updateHeight() {
|
|
||||||
if (this.rendition && this.rendition.resize) {
|
|
||||||
this.rendition.resize(window.innerWidth, window.innerHeight - this.readerHeightOffset)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
prev() {
|
prev() {
|
||||||
if (this.rendition) {
|
if (this.rendition) {
|
||||||
this.rendition.prev()
|
this.rendition.prev()
|
||||||
|
@ -382,14 +378,54 @@ export default {
|
||||||
this.rendition.getContents().forEach((c) => {
|
this.rendition.getContents().forEach((c) => {
|
||||||
c.addStylesheetRules(this.themeRules)
|
c.addStylesheetRules(this.themeRules)
|
||||||
})
|
})
|
||||||
}
|
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
async screenOrientationChange() {
|
||||||
this.book?.destroy()
|
if (this.isRefreshingUI) return
|
||||||
|
this.isRefreshingUI = true
|
||||||
|
const windowWidth = window.innerWidth
|
||||||
|
this.refreshUI()
|
||||||
|
|
||||||
|
// Window width does not always change right away. Wait up to 250ms for a change.
|
||||||
|
// iPhone 10 on iOS 16 took between 100 - 200ms to update when going from portrait to landscape
|
||||||
|
// but landscape to portrait was immediate
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 50))
|
||||||
|
if (window.innerWidth !== windowWidth) {
|
||||||
|
this.refreshUI()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isRefreshingUI = false
|
||||||
|
},
|
||||||
|
refreshUI() {
|
||||||
|
if (this.rendition?.resize) {
|
||||||
|
this.rendition.resize(window.innerWidth, window.innerHeight - this.readerHeightOffset)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initEpub()
|
this.initEpub()
|
||||||
|
|
||||||
|
if (screen.orientation) {
|
||||||
|
// Not available on ios
|
||||||
|
screen.orientation.addEventListener('change', this.screenOrientationChange)
|
||||||
|
} else {
|
||||||
|
document.addEventListener('orientationchange', this.screenOrientationChange)
|
||||||
}
|
}
|
||||||
|
window.addEventListener('resize', this.screenOrientationChange)
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.book?.destroy()
|
||||||
|
|
||||||
|
if (screen.orientation) {
|
||||||
|
// Not available on ios
|
||||||
|
screen.orientation.removeEventListener('change', this.screenOrientationChange)
|
||||||
|
} else {
|
||||||
|
document.removeEventListener('orientationchange', this.screenOrientationChange)
|
||||||
|
}
|
||||||
|
window.removeEventListener('resize', this.screenOrientationChange)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue