@@ -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