Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit 524ff01

Browse files
Update scrolling position of current web view when changing the triptych index
1 parent ae33086 commit 524ff01

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

r2-navigator-swift/EPUB/TriptychView.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ final class TriptychView: UIView {
9797
}
9898

9999
/// Index of the document currently being displayed.
100-
fileprivate(set) var index: Int
100+
fileprivate(set) var index: Int {
101+
willSet {
102+
guard let cw = currentView as? DocumentWebView else {
103+
return
104+
}
105+
cw.scrollAt(location: (index < newValue) ? trailing : leading)
106+
}
107+
}
101108

102109
fileprivate let scrollView: UIScrollView
103110

@@ -357,11 +364,9 @@ extension TriptychView {
357364
if index < nextIndex {
358365
currentRect.x += coefficient*currentFrameSize.width
359366
scrollView.scrollRectToVisible(CGRect(origin: currentRect, size: currentFrameSize), animated: false)
360-
cw.scrollAt(location: trailing)
361367
} else {
362368
currentRect.x -= coefficient*currentFrameSize.width
363369
scrollView.scrollRectToVisible(CGRect(origin: currentRect, size: currentFrameSize), animated: false)
364-
cw.scrollAt(location: leading)
365370
}
366371

367372
let previousIndex = index

0 commit comments

Comments
 (0)