Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ All notable changes to this project will be documented in this file. Take a look

### Fixed

#### Navigator

* Fixed EPUB fixed-layout spread settings not updating after device rotation when the app was in the background.

#### LCP

* Fixed crash when an EPUB resource is declared as LCP-encrypted in the manifest but contains unencrypted data.
Expand Down
34 changes: 19 additions & 15 deletions Sources/Navigator/EPUB/EPUBNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ open class EPUBNavigatorViewController: InputObservableViewController,
@objc private func didBecomeActive() {
isActive = true

// The device may have rotated since the last time the app was active.
// We may need to refresh the spreads in this situation. Unfortunately,
// the `viewWillTransition(to:with:)` API is called before we receive
// the `didBecomeActive` notification, so we cannot rely on it here.
viewModel.viewSizeWillChange(view.bounds.size)

if needsReloadSpreadsOnActive {
needsReloadSpreadsOnActive = false
reloadSpreads(force: true)
Expand Down Expand Up @@ -449,10 +455,8 @@ open class EPUBNavigatorViewController: InputObservableViewController,
override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

viewModel.viewSizeWillChange(size)

coordinator.animate(alongsideTransition: nil) { [weak self] _ in
self?.reloadSpreads(force: false)
if isActive {
viewModel.viewSizeWillChange(size)
}
}

Expand Down Expand Up @@ -566,12 +570,20 @@ open class EPUBNavigatorViewController: InputObservableViewController,
private func reloadSpreads(force: Bool) {
guard
state != .initializing,
isViewLoaded,
isActive
isViewLoaded
else {
return
}

guard isActive else {
// If we reload the spreads while the app is in the background, the
// web view will reset to progression 0 instead of the current one.
// We need to wait for the application to return to the foreground
// to maintain the current location.
needsReloadSpreadsOnActive = true
return
}

_reloadSpreads(force: force)
}

Expand Down Expand Up @@ -1230,15 +1242,7 @@ extension EPUBNavigatorViewController: EPUBSpreadViewDelegate {
}

func spreadViewDidTerminate() {
if !isActive {
// If we reload the spreads while the app is in the background, the
// web view will reset to progression 0 instead of the current one.
// We need to wait for the application to return to the foreground
// to maintain the current location.
needsReloadSpreadsOnActive = true
} else {
reloadSpreads(force: true)
}
reloadSpreads(force: true)
}
}

Expand Down