From 7f1d01ae57533ea279f556d41e5ccc8be6f1e657 Mon Sep 17 00:00:00 2001 From: Emerson Carpes Date: Tue, 20 Dec 2016 11:50:56 -0200 Subject: [PATCH 1/4] Create variable hidePageIndicator to hide page indicator. --- Example/Example/ViewController.swift | 1 + Example/Podfile.lock | 4 ++-- Source/FolioReaderConfig.swift | 3 +++ Source/FolioReaderPageIndicator.swift | 5 ++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index 093e199af..3fa3cfea3 100755 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -43,6 +43,7 @@ class ViewController: UIViewController { // config.toolBarBackgroundColor = UIColor.purpleColor() // config.menuTextColor = UIColor.brownColor() // config.menuBackgroundColor = UIColor.lightGrayColor() +// config.hidePageIndicator = true // Custom sharing quote background let customImageQuote = QuoteImage(withImage: UIImage(named: "demo-bg")!, alpha: 0.6, backgroundColor: UIColor.black) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 1151bf6b9..aca5fead0 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -28,7 +28,7 @@ DEPENDENCIES: EXTERNAL SOURCES: FolioReaderKit: - :path: "../" + :path: ../ SPEC CHECKSUMS: AEXML: 6fc6433aa35bdc15dd8eb8d54eb7aa4520a010eb @@ -45,4 +45,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 591559c46a2b0a49e687795b8ae46fadbddf8fd4 -COCOAPODS: 1.1.1 +COCOAPODS: 1.2.0.beta.1 diff --git a/Source/FolioReaderConfig.swift b/Source/FolioReaderConfig.swift index 6ede9a8f3..57aaed84d 100755 --- a/Source/FolioReaderConfig.swift +++ b/Source/FolioReaderConfig.swift @@ -149,6 +149,9 @@ open class FolioReaderConfig: NSObject { /// Enable TTS (Text To Speech) open var enableTTS = true + // hide the page indicator + open var hidePageIndicator = false + // MARK: Quote image share /// Custom Quote logo diff --git a/Source/FolioReaderPageIndicator.swift b/Source/FolioReaderPageIndicator.swift index bc07c798b..2d8e777c5 100644 --- a/Source/FolioReaderPageIndicator.swift +++ b/Source/FolioReaderPageIndicator.swift @@ -80,9 +80,12 @@ class FolioReaderPageIndicator: UIView { pagesLabel.textColor = isNight(UIColor(white: 1, alpha: 0.6), UIColor(white: 0, alpha: 0.9)) } - fileprivate func reloadViewWithPage(_ page: Int) { + fileprivate func reloadViewWithPage(_ page: Int, _ hidePageIndicator:Bool = readerConfig.hidePageIndicator) { let pagesRemaining = FolioReader.needsRTLChange ? totalPages-(totalPages-page+1) : totalPages-page + pagesLabel.isHidden = hidePageIndicator + minutesLabel.isHidden = hidePageIndicator + if pagesRemaining == 1 { pagesLabel.text = " "+readerConfig.localizedReaderOnePageLeft } else { From db508bbe64a950e7cc0d3070334f9dac12a797d6 Mon Sep 17 00:00:00 2001 From: Emerson Carpes Date: Sun, 8 Jan 2017 22:39:20 -0200 Subject: [PATCH 2/4] Revert "Merge pull request #178 from revolter/hotfix/default-scroll-direction" This reverts commit 5b76502227c58b039412eeba7bc56599991633ef, reversing changes made to 3377280366b0e28b0012444bf94a7d230d272352. --- 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, 13 insertions(+), 29 deletions(-) diff --git a/Source/FolioReaderConfig.swift b/Source/FolioReaderConfig.swift index 57aaed84d..9b7003284 100755 --- a/Source/FolioReaderConfig.swift +++ b/Source/FolioReaderConfig.swift @@ -23,10 +23,7 @@ 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 @@ -34,7 +31,7 @@ public enum FolioReaderScrollDirection: Int { */ func collectionViewScrollDirection() -> UICollectionViewScrollDirection { switch self { - case .vertical, .defaultVertical: + case .vertical: return .vertical case .horizontal, .horizontalWithVerticalContent: return .horizontal @@ -135,7 +132,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 = .defaultVertical + open var scrollDirection: FolioReaderScrollDirection = .vertical /// 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 178ca092f..dfb832279 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.defaultVertical.rawValue + kCurrentScrollDirection: FolioReaderScrollDirection.vertical.rawValue ]) } @@ -95,13 +95,8 @@ open class FolioReaderContainer: UIViewController { // If user can change scroll direction use the last saved if readerConfig.canChangeScrollDirection { - var scrollDirection = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection) ?? .vertical - - if (scrollDirection == .defaultVertical && readerConfig.scrollDirection != .defaultVertical) { - scrollDirection = readerConfig.scrollDirection - } - - readerConfig.scrollDirection = scrollDirection + let direction = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection) ?? .vertical + readerConfig.scrollDirection = direction } readerConfig.shouldHideNavigationOnTap = ((readerConfig.hideBars == true) ? true : readerConfig.shouldHideNavigationOnTap) diff --git a/Source/FolioReaderFontsMenu.swift b/Source/FolioReaderFontsMenu.swift index b61f261bb..64856fb09 100644 --- a/Source/FolioReaderFontsMenu.swift +++ b/Source/FolioReaderFontsMenu.swift @@ -234,14 +234,7 @@ class FolioReaderFontsMenu: UIViewController, SMSegmentViewDelegate, UIGestureRe layoutDirection.tag = 3 layoutDirection.addSegmentWithTitle(readerConfig.localizedLayoutVertical, onSelectionImage: verticalSelected, offSelectionImage: verticalNormal) layoutDirection.addSegmentWithTitle(readerConfig.localizedLayoutHorizontal, onSelectionImage: horizontalSelected, offSelectionImage: horizontalNormal) - - var scrollDirection = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection) - - if scrollDirection == .defaultVertical && readerConfig.scrollDirection != .defaultVertical { - scrollDirection = readerConfig.scrollDirection - } - - layoutDirection.selectSegmentAtIndex(scrollDirection?.rawValue ?? 0) + layoutDirection.selectSegmentAtIndex(Int(FolioReader.currentScrollDirection)) menuView.addSubview(layoutDirection) } diff --git a/Source/FolioReaderKit.swift b/Source/FolioReaderKit.swift index 5b68f8524..2fdcef129 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) ?? .defaultVertical + let direction = FolioReaderScrollDirection(rawValue: currentScrollDirection) ?? .vertical _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, .defaultVertical: return vertical + case .vertical: return vertical case .horizontal: return horizontal case .horizontalWithVerticalContent: return horizontalContentVertical ?? vertical } diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index e16f605f9..194ef8a01 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -396,8 +396,7 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe if !anchor.isEmpty { let offset = getAnchorOffset(anchor) - switch readerConfig.scrollDirection { - case .vertical, .defaultVertical: + if readerConfig.scrollDirection == .vertical { let isBeginning = offset < frame.forDirection()/2 if !avoidBeginningAnchors { @@ -405,7 +404,7 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe } else if avoidBeginningAnchors && !isBeginning { scrollPageToOffset(offset, animated: animated) } - case .horizontal, .horizontalWithVerticalContent: + } else { scrollPageToOffset(offset, animated: animated) } } diff --git a/Source/FolioReaderWebView.swift b/Source/FolioReaderWebView.swift index 6f3733660..5505857a1 100644 --- a/Source/FolioReaderWebView.swift +++ b/Source/FolioReaderWebView.swift @@ -280,7 +280,7 @@ open class FolioReaderWebView: UIWebView { func setupScrollDirection() { switch readerConfig.scrollDirection { - case .vertical, .defaultVertical, .horizontalWithVerticalContent: + case .vertical, .horizontalWithVerticalContent: scrollView.isPagingEnabled = false paginationMode = .unpaginated scrollView.bounces = true diff --git a/Source/ScrollScrubber.swift b/Source/ScrollScrubber.swift index edba98c42..be5a91155 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 == .defaultVertical || readerConfig.scrollDirection == .horizontalWithVerticalContent else { + guard readerConfig.scrollDirection == .vertical || readerConfig.scrollDirection == .horizontalWithVerticalContent else { return } From 5668a265708443e72896cb26c16b093ba9d9ea14 Mon Sep 17 00:00:00 2001 From: Emerson Carpes Date: Sun, 8 Jan 2017 23:23:55 -0200 Subject: [PATCH 3/4] Create variable hidePageIndicator to hide page indicator. --- Example/Podfile.lock | 2 +- Source/FolioReaderCenter.swift | 10 ++++++---- Source/FolioReaderPageIndicator.swift | 5 +---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index aca5fead0..4fbc70f6d 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -45,4 +45,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 591559c46a2b0a49e687795b8ae46fadbddf8fd4 -COCOAPODS: 1.2.0.beta.1 +COCOAPODS: 1.1.1 diff --git a/Source/FolioReaderCenter.swift b/Source/FolioReaderCenter.swift index 024e29f74..d1f656b6b 100755 --- a/Source/FolioReaderCenter.swift +++ b/Source/FolioReaderCenter.swift @@ -163,10 +163,12 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl configureNavBar() // Page indicator view - pageIndicatorView = FolioReaderPageIndicator(frame: self.frameForPageIndicatorView()) - if let pageIndicatorView = pageIndicatorView { - view.addSubview(pageIndicatorView) - } + if !readerConfig.hidePageIndicator { + pageIndicatorView = FolioReaderPageIndicator(frame: self.frameForPageIndicatorView()) + if let pageIndicatorView = pageIndicatorView { + view.addSubview(pageIndicatorView) + } + } scrollScrubber = ScrollScrubber(frame: self.frameForScrollScrubber()) scrollScrubber?.delegate = self diff --git a/Source/FolioReaderPageIndicator.swift b/Source/FolioReaderPageIndicator.swift index 2d8e777c5..bc07c798b 100644 --- a/Source/FolioReaderPageIndicator.swift +++ b/Source/FolioReaderPageIndicator.swift @@ -80,12 +80,9 @@ class FolioReaderPageIndicator: UIView { pagesLabel.textColor = isNight(UIColor(white: 1, alpha: 0.6), UIColor(white: 0, alpha: 0.9)) } - fileprivate func reloadViewWithPage(_ page: Int, _ hidePageIndicator:Bool = readerConfig.hidePageIndicator) { + fileprivate func reloadViewWithPage(_ page: Int) { let pagesRemaining = FolioReader.needsRTLChange ? totalPages-(totalPages-page+1) : totalPages-page - pagesLabel.isHidden = hidePageIndicator - minutesLabel.isHidden = hidePageIndicator - if pagesRemaining == 1 { pagesLabel.text = " "+readerConfig.localizedReaderOnePageLeft } else { From 2cfa743ff56eb542bd0c47772ce19099ac01ae2d Mon Sep 17 00:00:00 2001 From: Emerson Carpes Date: Sun, 8 Jan 2017 23:33:19 -0200 Subject: [PATCH 4/4] 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 }