Skip to content

Commit a151710

Browse files
committed
Fix updating the scroll view when changing the settings
1 parent 3e7cb78 commit a151710

File tree

6 files changed

+25
-85
lines changed

6 files changed

+25
-85
lines changed

CHANGELOG.md

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

99
* The Readium Swift toolkit now requires a minimum of iOS 13.4.
1010

11+
### Added
12+
13+
#### Navigator
14+
15+
* The `EPUBNavigatorViewController.Configuration.disablePageTurnsWhileScrolling` property disables horizontal swipes for navigating to previous or next resources when scroll mode is enabled. When set to `true`, you must implement your own mechanism to move to the next resource (contributed by [@alecdhansen](https://github.com/readium/swift-toolkit/pull/531)).
16+
1117
### Changed
1218

1319
#### Shared

Package.resolved

Lines changed: 0 additions & 69 deletions
This file was deleted.

Sources/Navigator/EPUB/EPUBNavigatorViewController.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ open class EPUBNavigatorViewController: UIViewController,
6868
/// `UIViewController` wrapping the `EPUBNavigatorViewController`.
6969
public var editingActions: [EditingAction]
7070

71+
/// Disables horizontal page turning when scroll is enabled.
72+
public var disablePageTurnsWhileScrolling: Bool
73+
7174
/// Content insets used to add some vertical margins around reflowable EPUB publications.
7275
/// The insets can be configured for each size class to allow smaller margins on compact
7376
/// screens.
@@ -92,14 +95,12 @@ open class EPUBNavigatorViewController: UIViewController,
9295

9396
/// Logs the state changes when true.
9497
public var debugState: Bool
95-
96-
/// Disables horizontal page turning when scroll is enabled.
97-
public let disablePageTurnsWhileScrolling: Bool
98-
98+
9999
public init(
100100
preferences: EPUBPreferences = .empty,
101101
defaults: EPUBDefaults = EPUBDefaults(),
102102
editingActions: [EditingAction] = EditingAction.defaultActions,
103+
disablePageTurnsWhileScrolling: Bool = false,
103104
contentInset: [UIUserInterfaceSizeClass: EPUBContentInsets] = [
104105
.compact: (top: 20, bottom: 20),
105106
.regular: (top: 44, bottom: 44),
@@ -109,20 +110,19 @@ open class EPUBNavigatorViewController: UIViewController,
109110
decorationTemplates: [Decoration.Style.Id: HTMLDecorationTemplate] = HTMLDecorationTemplate.defaultTemplates(),
110111
fontFamilyDeclarations: [AnyHTMLFontFamilyDeclaration] = [],
111112
readiumCSSRSProperties: CSSRSProperties = CSSRSProperties(),
112-
debugState: Bool = false,
113-
disablePageTurnsWhileScrolling: Bool = false
113+
debugState: Bool = false
114114
) {
115115
self.preferences = preferences
116116
self.defaults = defaults
117117
self.editingActions = editingActions
118+
self.disablePageTurnsWhileScrolling = disablePageTurnsWhileScrolling
118119
self.contentInset = contentInset
119120
self.preloadPreviousPositionCount = preloadPreviousPositionCount
120121
self.preloadNextPositionCount = preloadNextPositionCount
121122
self.decorationTemplates = decorationTemplates
122123
self.fontFamilyDeclarations = fontFamilyDeclarations
123124
self.readiumCSSRSProperties = readiumCSSRSProperties
124125
self.debugState = debugState
125-
self.disablePageTurnsWhileScrolling = disablePageTurnsWhileScrolling
126126
}
127127
}
128128

@@ -522,7 +522,7 @@ open class EPUBNavigatorViewController: UIViewController,
522522
frame: .zero,
523523
preloadPreviousPositionCount: hasPositions ? config.preloadPreviousPositionCount : 0,
524524
preloadNextPositionCount: hasPositions ? config.preloadNextPositionCount : 0,
525-
isScrollEnabled: isPaginationViewScrollingEnabled(with: settings)
525+
isScrollEnabled: isPaginationViewScrollingEnabled
526526
)
527527
view.delegate = self
528528
view.backgroundColor = .clear
@@ -614,10 +614,10 @@ open class EPUBNavigatorViewController: UIViewController,
614614

615615
// MARK: - Navigator
616616

617-
private func isPaginationViewScrollingEnabled(with settings: EPUBSettings) -> Bool {
617+
private var isPaginationViewScrollingEnabled: Bool {
618618
!(config.disablePageTurnsWhileScrolling && settings.scroll)
619619
}
620-
620+
621621
public var presentation: VisualNavigatorPresentation {
622622
VisualNavigatorPresentation(
623623
readingProgression: settings.readingProgression,
@@ -854,6 +854,7 @@ open class EPUBNavigatorViewController: UIViewController,
854854
}
855855

856856
view.backgroundColor = settings.effectiveBackgroundColor.uiColor
857+
paginationView.isScrollEnabled = isPaginationViewScrollingEnabled
857858
}
858859

859860
// MARK: - User interactions
@@ -912,7 +913,7 @@ open class EPUBNavigatorViewController: UIViewController,
912913
extension EPUBNavigatorViewController: EPUBNavigatorViewModelDelegate {
913914
func epubNavigatorViewModelInvalidatePaginationView(_ viewModel: EPUBNavigatorViewModel) {
914915
Task {
915-
paginationView.isScrollEnabled = isPaginationViewScrollingEnabled(with: viewModel.settings)
916+
paginationView.isScrollEnabled = isPaginationViewScrollingEnabled
916917
await reloadSpreads(force: true)
917918
}
918919
}

Sources/Navigator/Toolkit/PaginationView.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ final class PaginationView: UIView, Loggable {
9494
private let scrollView = UIScrollView()
9595

9696
/// Allows the scroll view to scroll.
97-
var isScrollEnabled: Bool
98-
97+
var isScrollEnabled: Bool {
98+
didSet { scrollView.isScrollEnabled = isScrollEnabled }
99+
}
100+
99101
init(
100102
frame: CGRect,
101103
preloadPreviousPositionCount: Int,
@@ -105,7 +107,7 @@ final class PaginationView: UIView, Loggable {
105107
self.preloadPreviousPositionCount = preloadPreviousPositionCount
106108
self.preloadNextPositionCount = preloadNextPositionCount
107109
self.isScrollEnabled = isScrollEnabled
108-
110+
109111
super.init(frame: frame)
110112

111113
scrollView.delegate = self

Sources/Shared/Toolkit/HTTP/DefaultHTTPClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public final class DefaultHTTPClient: HTTPClient, Loggable {
429429
return
430430
}
431431

432-
var response = HTTPResponse(request: request, response: urlResponse, url: url)
432+
let response = HTTPResponse(request: request, response: urlResponse, url: url)
433433

434434
guard response.status.isSuccess else {
435435
state = .failure(continuation: continuation, error: .errorResponse(response))

TestApp/Sources/Reader/EPUB/EPUBViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class EPUBViewController: VisualReaderViewController<EPUBNavigatorViewController
3737
let navigator = try EPUBNavigatorViewController(
3838
publication: publication,
3939
initialLocation: locator,
40-
config: .init(
40+
config: EPUBNavigatorViewController.Configuration(
4141
preferences: initialPreferences,
4242
editingActions: EditingAction.defaultActions
4343
.appending(EditingAction(

0 commit comments

Comments
 (0)