Skip to content

Commit db12e1e

Browse files
authored
Fix FXL auto spread settings after rotating the device (#675)
1 parent bd3b3f0 commit db12e1e

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ All notable changes to this project will be documented in this file. Take a look
2121

2222
### Fixed
2323

24+
#### Navigator
25+
26+
* Fixed EPUB fixed-layout spread settings not updating after device rotation when the app was in the background.
27+
2428
#### LCP
2529

2630
* Fixed crash when an EPUB resource is declared as LCP-encrypted in the manifest but contains unencrypted data.

Sources/Navigator/EPUB/EPUBNavigatorViewController.swift

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ open class EPUBNavigatorViewController: InputObservableViewController,
390390
@objc private func didBecomeActive() {
391391
isActive = true
392392

393+
// The device may have rotated since the last time the app was active.
394+
// We may need to refresh the spreads in this situation. Unfortunately,
395+
// the `viewWillTransition(to:with:)` API is called before we receive
396+
// the `didBecomeActive` notification, so we cannot rely on it here.
397+
viewModel.viewSizeWillChange(view.bounds.size)
398+
393399
if needsReloadSpreadsOnActive {
394400
needsReloadSpreadsOnActive = false
395401
reloadSpreads(force: true)
@@ -449,10 +455,8 @@ open class EPUBNavigatorViewController: InputObservableViewController,
449455
override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
450456
super.viewWillTransition(to: size, with: coordinator)
451457

452-
viewModel.viewSizeWillChange(size)
453-
454-
coordinator.animate(alongsideTransition: nil) { [weak self] _ in
455-
self?.reloadSpreads(force: false)
458+
if isActive {
459+
viewModel.viewSizeWillChange(size)
456460
}
457461
}
458462

@@ -566,12 +570,20 @@ open class EPUBNavigatorViewController: InputObservableViewController,
566570
private func reloadSpreads(force: Bool) {
567571
guard
568572
state != .initializing,
569-
isViewLoaded,
570-
isActive
573+
isViewLoaded
571574
else {
572575
return
573576
}
574577

578+
guard isActive else {
579+
// If we reload the spreads while the app is in the background, the
580+
// web view will reset to progression 0 instead of the current one.
581+
// We need to wait for the application to return to the foreground
582+
// to maintain the current location.
583+
needsReloadSpreadsOnActive = true
584+
return
585+
}
586+
575587
_reloadSpreads(force: force)
576588
}
577589

@@ -1230,15 +1242,7 @@ extension EPUBNavigatorViewController: EPUBSpreadViewDelegate {
12301242
}
12311243

12321244
func spreadViewDidTerminate() {
1233-
if !isActive {
1234-
// If we reload the spreads while the app is in the background, the
1235-
// web view will reset to progression 0 instead of the current one.
1236-
// We need to wait for the application to return to the foreground
1237-
// to maintain the current location.
1238-
needsReloadSpreadsOnActive = true
1239-
} else {
1240-
reloadSpreads(force: true)
1241-
}
1245+
reloadSpreads(force: true)
12421246
}
12431247
}
12441248

0 commit comments

Comments
 (0)