From 85eaf47f179b50069594c5f7c52b02bced66942e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Mon, 1 Dec 2025 18:44:02 +0100 Subject: [PATCH] Fix FXL auto spread settings after rotating the device --- CHANGELOG.md | 4 +++ .../EPUB/EPUBNavigatorViewController.swift | 34 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 455406384..035f6820e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift b/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift index 55ffe5b31..aab8d1393 100644 --- a/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift +++ b/Sources/Navigator/EPUB/EPUBNavigatorViewController.swift @@ -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) @@ -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) } } @@ -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) } @@ -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) } }