Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #178 from revolter/hotfix/default-scroll-direction
Browse files Browse the repository at this point in the history
Fix scroll direction being ignored on first run
  • Loading branch information
hebertialmeida committed Dec 9, 2016
2 parents 3377280 + b8c67ad commit 5b76502
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
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
])
}

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

if (scrollDirection == .defaultVertical && readerConfig.scrollDirection != .defaultVertical) {
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)

if scrollDirection == .defaultVertical && readerConfig.scrollDirection != .defaultVertical {
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 @@ -164,7 +164,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 @@ -277,7 +277,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 @@ -280,7 +280,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

0 comments on commit 5b76502

Please sign in to comment.