Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Source/FolioReaderConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ public enum FolioReaderScrollDirection: Int {

/// Sections scroll horizontal and content scroll on vertical
case horizontalWithVerticalContent


/// The default scroll direction, if not overridden; works as .vertical
case defaultVertical

/**
The current scroll direction

- returns: Returns `UICollectionViewScrollDirection`
*/
func collectionViewScrollDirection() -> UICollectionViewScrollDirection {
switch self {
case .vertical:
case .vertical, .defaultVertical:
return .vertical
case .horizontal, .horizontalWithVerticalContent:
return .horizontal
Expand Down Expand Up @@ -132,7 +135,7 @@ open class FolioReaderConfig: NSObject {
open var hideBars = false

/// If `canChangeScrollDirection` is `true` it will be overrided by user's option.
open var scrollDirection: FolioReaderScrollDirection = .vertical
open var scrollDirection: FolioReaderScrollDirection = .defaultVertical

/// Enable or disable hability to user change scroll direction on menu.
open var canChangeScrollDirection = true
Expand Down
11 changes: 8 additions & 3 deletions Source/FolioReaderContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ open class FolioReaderContainer: UIViewController {
kCurrentHighlightStyle: 0,
kCurrentTOCMenu: 0,
kCurrentMediaOverlayStyle: MediaOverlayStyle.default.rawValue,
kCurrentScrollDirection: FolioReaderScrollDirection.vertical.rawValue
kCurrentScrollDirection: FolioReaderScrollDirection.defaultVertical.rawValue
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sure the initial value of the scroll direction is the new .defaultVertical, and not .vertical. This default value works as vertical if the user doesn't sets another value for the config's scroll direction.

])
}

Expand All @@ -95,8 +95,13 @@ open class FolioReaderContainer: UIViewController {

// If user can change scroll direction use the last saved
if readerConfig.canChangeScrollDirection {
let direction = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection) ?? .vertical
readerConfig.scrollDirection = direction
var scrollDirection = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection) ?? .vertical
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loads the persisted scroll direction, which, in the first app run, is .defaultVertical as set by the line #72.


if (scrollDirection == .defaultVertical && readerConfig.scrollDirection != .defaultVertical) {
Copy link
Copy Markdown
Member Author

@revolter revolter Dec 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the persisted value is .defaultVertical, meaning this is the first app run, and the user has set a scroll direction different from the default one, use the user's scroll direction.

scrollDirection = readerConfig.scrollDirection
}

readerConfig.scrollDirection = scrollDirection
}

readerConfig.shouldHideNavigationOnTap = ((readerConfig.hideBars == true) ? true : readerConfig.shouldHideNavigationOnTap)
Expand Down
9 changes: 8 additions & 1 deletion Source/FolioReaderFontsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,14 @@ class FolioReaderFontsMenu: UIViewController, SMSegmentViewDelegate, UIGestureRe
layoutDirection.tag = 3
layoutDirection.addSegmentWithTitle(readerConfig.localizedLayoutVertical, onSelectionImage: verticalSelected, offSelectionImage: verticalNormal)
layoutDirection.addSegmentWithTitle(readerConfig.localizedLayoutHorizontal, onSelectionImage: horizontalSelected, offSelectionImage: horizontalNormal)
layoutDirection.selectSegmentAtIndex(Int(FolioReader.currentScrollDirection))

var scrollDirection = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't remember why didn't it require me to add ?? .vertical here too, as on the line #98.


if scrollDirection == .defaultVertical && readerConfig.scrollDirection != .defaultVertical {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as this comment.

scrollDirection = readerConfig.scrollDirection
}

layoutDirection.selectSegmentAtIndex(scrollDirection?.rawValue ?? 0)
menuView.addSubview(layoutDirection)
}

Expand Down
4 changes: 2 additions & 2 deletions Source/FolioReaderKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ open class FolioReader: NSObject {
FolioReader.defaults.setValue(value, forKey: kCurrentScrollDirection)

if let _readerCenter = FolioReader.shared.readerCenter {
let direction = FolioReaderScrollDirection(rawValue: currentScrollDirection) ?? .vertical
let direction = FolioReaderScrollDirection(rawValue: currentScrollDirection) ?? .defaultVertical
_readerCenter.setScrollDirection(direction)
}
}
Expand Down Expand Up @@ -266,7 +266,7 @@ func isNight<T> (_ f: T, _ l: T) -> T {
*/
func isDirection<T> (_ vertical: T, _ horizontal: T, _ horizontalContentVertical: T? = nil) -> T {
switch readerConfig.scrollDirection {
case .vertical: return vertical
case .vertical, .defaultVertical: return vertical
case .horizontal: return horizontal
case .horizontalWithVerticalContent: return horizontalContentVertical ?? vertical
}
Expand Down
5 changes: 3 additions & 2 deletions Source/FolioReaderPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,16 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe
if !anchor.isEmpty {
let offset = getAnchorOffset(anchor)

if readerConfig.scrollDirection == .vertical {
switch readerConfig.scrollDirection {
case .vertical, .defaultVertical:
let isBeginning = offset < frame.forDirection()/2

if !avoidBeginningAnchors {
scrollPageToOffset(offset, animated: animated)
} else if avoidBeginningAnchors && !isBeginning {
scrollPageToOffset(offset, animated: animated)
}
} else {
case .horizontal, .horizontalWithVerticalContent:
scrollPageToOffset(offset, animated: animated)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/FolioReaderWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ open class FolioReaderWebView: UIWebView {

func setupScrollDirection() {
switch readerConfig.scrollDirection {
case .vertical, .horizontalWithVerticalContent:
case .vertical, .defaultVertical, .horizontalWithVerticalContent:
scrollView.isPagingEnabled = false
paginationMode = .unpaginated
scrollView.bounces = true
Expand Down
2 changes: 1 addition & 1 deletion Source/ScrollScrubber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ScrollScrubber: NSObject, UIScrollViewDelegate {
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard readerConfig.scrollDirection == .vertical || readerConfig.scrollDirection == .horizontalWithVerticalContent else {
guard readerConfig.scrollDirection == .vertical || readerConfig.scrollDirection == .defaultVertical || readerConfig.scrollDirection == .horizontalWithVerticalContent else {
return
}

Expand Down