Skip to content

Commit 79d802a

Browse files
authored
Adjust safe area insets strategy for 26 (#650)
1 parent eaa2bd6 commit 79d802a

File tree

5 files changed

+27
-47
lines changed

5 files changed

+27
-47
lines changed

CHANGELOG.md

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

1111
* The LCP License Document is now accessible via `publication.lcpLicense?.license`, even if the license validation fails with a status error or missing passphrase. This is useful for checking the end date of an expired license or renew a license.
1212

13+
### Fixed
14+
15+
#### Navigator
16+
17+
* The safe area insets strategy was adjusted to take into account changes in iOS/iPadOS 26.
18+
1319

1420
## [3.4.0]
1521

Sources/Navigator/EPUB/EPUBFixedSpreadView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ final class EPUBFixedSpreadView: EPUBSpreadView {
7878
return
7979
}
8080

81-
// Insets the bounds by the notch area (eg. iPhone X) to make sure that
82-
// the content is not overlapped by the screen notch.
83-
var insets = notchAreaInsets
81+
// We use the window's safeAreaInsets instead of the view's because we
82+
// only want to take into account the device notch and status bar, not
83+
// the application's bars.
84+
var insets = window?.safeAreaInsets ?? .zero
8485

8586
// Use the same insets on the left and right side (the largest one) to
8687
// keep the pages centered on the screen even if the notches are not

Sources/Navigator/EPUB/EPUBReflowableSpreadView.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ final class EPUBReflowableSpreadView: EPUBSpreadView {
8686
}
8787

8888
private func updateContentInset() {
89+
// We use the window's safeAreaInsets instead of the view's because we
90+
// only want to take into account the device notch and status bar, not
91+
// the application's bars.
92+
let safeAreaInsets = window?.safeAreaInsets ?? .zero
93+
8994
if viewModel.scroll {
9095
topConstraint.constant = 0
9196
bottomConstraint.constant = 0
92-
scrollView.contentInset = UIEdgeInsets(top: notchAreaInsets.top, left: 0, bottom: notchAreaInsets.bottom, right: 0)
97+
scrollView.contentInset = UIEdgeInsets(top: safeAreaInsets.top, left: 0, bottom: safeAreaInsets.bottom, right: 0)
9398

9499
} else {
95100
let contentInset = viewModel.config.contentInset
@@ -98,9 +103,10 @@ final class EPUBReflowableSpreadView: EPUBSpreadView {
98103
?? contentInset[.unspecified]
99104
?? (top: 0, bottom: 0)
100105

101-
// Increases the insets by the notch area (eg. iPhone X) to make sure that the content is not overlapped by the screen notch.
102-
insets.top += notchAreaInsets.top
103-
insets.bottom += notchAreaInsets.bottom
106+
// Increases the insets by the window's safe area insets area to
107+
// make sure that the content is not overlapped by the screen notch.
108+
insets.top += safeAreaInsets.top
109+
insets.bottom += safeAreaInsets.bottom
104110

105111
topConstraint.constant = insets.top
106112
bottomConstraint.constant = -insets.bottom

Sources/Navigator/PDF/PDFDocumentView.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ public final class PDFDocumentView: PDFView {
4040
}
4141

4242
private func updateContentInset() {
43-
// Setting the horizontal values triggers shifts the content incorrectly, somehow.
44-
firstScrollView?.contentInset.top = notchAreaInsets.top
45-
firstScrollView?.contentInset.bottom = notchAreaInsets.bottom
43+
// We use the window's safeAreaInsets instead of the view's because we
44+
// only want to take into account the device notch and status bar, not
45+
// the application's bars.
46+
let insets = window?.safeAreaInsets ?? .zero
47+
48+
firstScrollView?.contentInset.top = insets.top
49+
firstScrollView?.contentInset.bottom = insets.bottom
4650
}
4751

4852
override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {

Sources/Navigator/Toolkit/Extensions/UIView.swift

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,6 @@ import Foundation
88
import UIKit
99

1010
extension UIView {
11-
/// Returns the safe area insets taking only into account the device screen notches (eg. on
12-
/// iPhone X), ignoring any UX safe area insets (eg. status bar, navigation bar).
13-
///
14-
/// This can be used to layout the content in a way that makes sure it's not under the physical
15-
/// notches, but at the same time is under the status and navigation bars (which is usually what
16-
/// we want for a reader app).
17-
///
18-
/// We use that instead of pinning the content directly to the safe area layout guides to avoid
19-
/// the view shifting when the status bar is toggled.
20-
var notchAreaInsets: UIEdgeInsets {
21-
guard let window = window else {
22-
return safeAreaInsets
23-
}
24-
25-
var windowSafeAreaInsets = window.safeAreaInsets
26-
27-
// Trick to ignore the status bar on devices without notches (pre iPhone X).
28-
// Notch height is usually at least 44pts tall.
29-
let statusBarSize = window.windowScene?.statusBarManager?.statusBarFrame.size ?? .zero
30-
// The frame is in the coordinate space of the window, so it might be swapped in landscape.
31-
let statusBarHeight = min(statusBarSize.width, statusBarSize.height)
32-
if statusBarHeight < 44, windowSafeAreaInsets.top == statusBarHeight {
33-
windowSafeAreaInsets.top = 0
34-
}
35-
36-
// We take the smallest value between the view's safeAreaInsets and the window's
37-
// safeAreaInsets in case the view is not pinned to the screen edges. In which case, its
38-
// safeAreaInsets will likely be empty and we don't want to take into account the screen
39-
// notch.
40-
return UIEdgeInsets(
41-
top: min(windowSafeAreaInsets.top, safeAreaInsets.top),
42-
left: min(windowSafeAreaInsets.left, safeAreaInsets.left),
43-
bottom: min(windowSafeAreaInsets.bottom, safeAreaInsets.bottom),
44-
right: min(windowSafeAreaInsets.right, safeAreaInsets.right)
45-
)
46-
}
47-
4811
// Finds the first `UIScrollView` in the view hierarchy.
4912
//
5013
// https://medium.com/@wailord/the-particulars-of-the-safe-area-and-contentinsetadjustmentbehavior-in-ios-11-9b842018eeaa#077b

0 commit comments

Comments
 (0)