From 2cfa743ff56eb542bd0c47772ce19099ac01ae2d Mon Sep 17 00:00:00 2001 From: Emerson Carpes Date: Sun, 8 Jan 2017 23:33:19 -0200 Subject: [PATCH] Revert "Revert "Merge pull request #178 from revolter/hotfix/default-scroll-direction"" This reverts commit db508bbe64a950e7cc0d3070334f9dac12a797d6. --- Source/FolioReaderConfig.swift | 9 ++++++--- Source/FolioReaderContainer.swift | 11 ++++++++--- Source/FolioReaderFontsMenu.swift | 9 ++++++++- Source/FolioReaderKit.swift | 4 ++-- Source/FolioReaderPage.swift | 5 +++-- Source/FolioReaderWebView.swift | 2 +- Source/ScrollScrubber.swift | 2 +- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Source/FolioReaderConfig.swift b/Source/FolioReaderConfig.swift index 9b7003284..57aaed84d 100755 --- a/Source/FolioReaderConfig.swift +++ b/Source/FolioReaderConfig.swift @@ -23,7 +23,10 @@ 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 @@ -31,7 +34,7 @@ public enum FolioReaderScrollDirection: Int { */ func collectionViewScrollDirection() -> UICollectionViewScrollDirection { switch self { - case .vertical: + case .vertical, .defaultVertical: return .vertical case .horizontal, .horizontalWithVerticalContent: return .horizontal @@ -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 diff --git a/Source/FolioReaderContainer.swift b/Source/FolioReaderContainer.swift index dfb832279..178ca092f 100755 --- a/Source/FolioReaderContainer.swift +++ b/Source/FolioReaderContainer.swift @@ -69,7 +69,7 @@ open class FolioReaderContainer: UIViewController { kCurrentHighlightStyle: 0, kCurrentTOCMenu: 0, kCurrentMediaOverlayStyle: MediaOverlayStyle.default.rawValue, - kCurrentScrollDirection: FolioReaderScrollDirection.vertical.rawValue + kCurrentScrollDirection: FolioReaderScrollDirection.defaultVertical.rawValue ]) } @@ -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) diff --git a/Source/FolioReaderFontsMenu.swift b/Source/FolioReaderFontsMenu.swift index 64856fb09..b61f261bb 100644 --- a/Source/FolioReaderFontsMenu.swift +++ b/Source/FolioReaderFontsMenu.swift @@ -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) } diff --git a/Source/FolioReaderKit.swift b/Source/FolioReaderKit.swift index 2fdcef129..5b68f8524 100755 --- a/Source/FolioReaderKit.swift +++ b/Source/FolioReaderKit.swift @@ -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) } } @@ -277,7 +277,7 @@ func isNight (_ f: T, _ l: T) -> T { */ func isDirection (_ 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 } diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index 63a9c25b0..8b40a3328 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -397,7 +397,8 @@ 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 { @@ -405,7 +406,7 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe } else if avoidBeginningAnchors && !isBeginning { scrollPageToOffset(offset, animated: animated) } - } else { + case .horizontal, .horizontalWithVerticalContent: scrollPageToOffset(offset, animated: animated) } } diff --git a/Source/FolioReaderWebView.swift b/Source/FolioReaderWebView.swift index 5505857a1..6f3733660 100644 --- a/Source/FolioReaderWebView.swift +++ b/Source/FolioReaderWebView.swift @@ -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 diff --git a/Source/ScrollScrubber.swift b/Source/ScrollScrubber.swift index be5a91155..edba98c42 100644 --- a/Source/ScrollScrubber.swift +++ b/Source/ScrollScrubber.swift @@ -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 }