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

variable hideBars, scroll to navigate through paragraphs and scroll to read the content are added, README.md is updated #107

Merged
merged 12 commits into from
Aug 12, 2016
Merged
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ Then, follow the steps as described in Carthage's [README](https://github.com/Ca

## Basic Usage

To get started, this is a simple usage sample.
To get started, this is a simple usage sample of using the integrated view controller.

```swift
import FolioReaderKit
@@ -68,6 +68,19 @@ func open(sender: AnyObject) {
}
```

You can also use your own FolioReader view controller like this.

```swift
let config = FolioReaderConfig()

let bookPath = NSBundle.mainBundle().pathForResource("book", ofType: "epub")
let epubVC = FolioReaderContainer(config: config, epubPath: bookPath, removeEpub: true)
Copy link
Member

Choose a reason for hiding this comment

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

Have you tested this? This init is not public, we need to make it public to work.

Copy link
Member

Choose a reason for hiding this comment

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

This init still not public yet, we have to make it public on FolioReaderContainer.

public init(config configOrNil: FolioReaderConfig!, epubPath epubPathOrNil: String? = nil, removeEpub: Bool) {

FolioReader.sharedInstance.readerContainer = epubVC
Copy link
Member

@hebertialmeida hebertialmeida Aug 10, 2016

Choose a reason for hiding this comment

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

sharedInstance is also not public, need to make public to work.

Maybe we can assign to the singleton inside the init, so on implementation will be simplified. There is no need to call FolioReader.sharedInstance.readerContainer = epubVC

What do you think?


// present the epubVC view controller like every other UIViewController instance
self.presentViewController(epubVC, animated: true, completion: nil)
```

In your AppDelegate call `applicationWillResignActive` and `applicationWillTerminate`. This will save the reader state even if you kill the app.

```swift
@@ -96,7 +109,7 @@ func applicationWillTerminate(application: UIApplication) {
- [x] Media Overlays (Sync text rendering with audio playback)
- [x] TTS - Text to Speech Support
- [x] Parse epub cover image
- [x] Vertical and Horizontal scrolling
- [x] Vertical or/and Horizontal scrolling
- [x] RTL Support
- [ ] PDF support
- [ ] Book Search
6 changes: 3 additions & 3 deletions Source/FolioReaderCenter.swift
Original file line number Diff line number Diff line change
@@ -31,15 +31,15 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
var animator: ZFModalTransitionAnimator!
var pageIndicatorView: FolioReaderPageIndicator!
var bookShareLink: String?

var pageIndicatorHeight: CGFloat = 20

var recentlyScrolled = false
var recentlyScrolledDelay = 2.0 // 2 second delay until we clear recentlyScrolled
var recentlyScrolledTimer: NSTimer!
var scrollScrubber: ScrollScrubber!

private var screenBounds: CGRect!
private var pointNow = CGPointZero
private let pageIndicatorHeight: CGFloat = 20
private var pageOffsetRate: CGFloat = 0
private var tempReference: FRTocReference?
private var isFirstLoad = true
@@ -87,7 +87,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
pageIndicatorView = FolioReaderPageIndicator(frame: CGRect(x: 0, y: view.frame.height-pageIndicatorHeight, width: view.frame.width, height: pageIndicatorHeight))
view.addSubview(pageIndicatorView)

let scrubberY: CGFloat = readerConfig.shouldHideNavigationOnTap == true ? 50 : 74
let scrubberY: CGFloat = ((readerConfig.shouldHideNavigationOnTap == true || readerConfig.hideBars == true) ? 50 : 74)
scrollScrubber = ScrollScrubber(frame: CGRect(x: pageWidth + 10, y: scrubberY, width: 40, height: pageHeight - 100))
scrollScrubber.delegate = self
view.addSubview(scrollScrubber.slider)
7 changes: 5 additions & 2 deletions Source/FolioReaderConfig.swift
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import UIKit
public enum FolioReaderScrollDirection: Int {
case vertical
case horizontal
case sectionHorizontalContentVertical
Copy link
Member

@hebertialmeida hebertialmeida Aug 10, 2016

Choose a reason for hiding this comment

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

This is a really interesting addition 👍

Some points that I have noticed:

  • The internal pages counter that show minutes and pages left is not working when using this option;
  • When using this option I think we have to disable canChangeScrollDirection, so by default this option has not ability to change the layout;
  • When open close book, the current reading position is not restored.

Sorry, something went wrong.


/**
The current scroll direction
@@ -21,7 +22,7 @@ public enum FolioReaderScrollDirection: Int {
switch self {
case vertical:
return .Vertical
case horizontal:
case horizontal, sectionHorizontalContentVertical:
return .Horizontal
}
}
@@ -41,7 +42,9 @@ public class FolioReaderConfig: NSObject {
public lazy var mediaOverlayColor: UIColor! = self.tintColor

// MARK: Custom actions

/// hide the navigation bar and the bottom status view
public var hideBars = false

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

26 changes: 17 additions & 9 deletions Source/FolioReaderContainer.swift
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ var readerConfig: FolioReaderConfig!
var epubPath: String?
var book: FRBook!

class FolioReaderContainer: UIViewController {
public class FolioReaderContainer: UIViewController {
var centerNavigationController: UINavigationController!
var centerViewController: FolioReaderCenter!
var audioPlayer: FolioReaderAudioPlayer!
@@ -23,7 +23,7 @@ class FolioReaderContainer: UIViewController {

// MARK: - Init

required init?(coder aDecoder: NSCoder) {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

@@ -54,15 +54,17 @@ class FolioReaderContainer: UIViewController {

// MARK: - View life cicle

override func viewDidLoad() {
override public func viewDidLoad() {
super.viewDidLoad()

// If user can change scroll direction use the last saved
if readerConfig.canChangeScrollDirection {
if (readerConfig.canChangeScrollDirection && readerConfig.scrollDirection != .sectionHorizontalContentVertical) {
let direction = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection) ?? .vertical
readerConfig.scrollDirection = direction
}


readerConfig.shouldHideNavigationOnTap = ((readerConfig.hideBars == true) ? true : readerConfig.shouldHideNavigationOnTap)

centerViewController = FolioReaderCenter()
FolioReader.sharedInstance.readerCenter = centerViewController

@@ -72,6 +74,12 @@ class FolioReaderContainer: UIViewController {
addChildViewController(centerNavigationController)
centerNavigationController.didMoveToParentViewController(self)

if (readerConfig.hideBars == true) {
readerConfig.shouldHideNavigationOnTap = false
self.navigationController?.navigationBar.hidden = true
self.centerViewController.pageIndicatorHeight = 0
}

// Read async book
if (epubPath != nil) {
let priority = DISPATCH_QUEUE_PRIORITY_HIGH
@@ -115,7 +123,7 @@ class FolioReaderContainer: UIViewController {
}
}

override func viewDidAppear(animated: Bool) {
override public func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

if errorOnLoad {
@@ -133,15 +141,15 @@ class FolioReaderContainer: UIViewController {

// MARK: - Status Bar

override func prefersStatusBarHidden() -> Bool {
override public func prefersStatusBarHidden() -> Bool {
return readerConfig.shouldHideNavigationOnTap == false ? false : shouldHideStatusBar
}

override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
override public func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return UIStatusBarAnimation.Slide
}

override func preferredStatusBarStyle() -> UIStatusBarStyle {
override public func preferredStatusBarStyle() -> UIStatusBarStyle {
return isNight(.LightContent, .Default)
}
}
41 changes: 25 additions & 16 deletions Source/FolioReaderPage.swift
Original file line number Diff line number Diff line change
@@ -78,21 +78,26 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni
}

func webViewFrame() -> CGRect {
let paddingTop: CGFloat = 20

if (readerConfig.hideBars == true) {
Copy link
Member

Choose a reason for hiding this comment

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

You can use guard here is more Swifty

Need to test, but something like this:

guard readerConfig.hideBars == false else { return UIScreen.mainScreen().bounds }

return UIScreen.mainScreen().bounds
}

let paddingTop: CGFloat = 20
let paddingBottom: CGFloat = 30
guard readerConfig.shouldHideNavigationOnTap else {
let statusbarHeight = UIApplication.sharedApplication().statusBarFrame.size.height
let navBarHeight = FolioReader.sharedInstance.readerCenter.navigationController?.navigationBar.frame.size.height
let navTotal = statusbarHeight + navBarHeight!
let newFrame = CGRect(
x: bounds.origin.x,
y: isVerticalDirection(bounds.origin.y + navTotal, bounds.origin.y + navTotal + paddingTop),
width: bounds.width,
height: isVerticalDirection(bounds.height - navTotal, bounds.height - navTotal - paddingTop - paddingBottom))
return newFrame
}

guard readerConfig.shouldHideNavigationOnTap else {
let statusbarHeight = UIApplication.sharedApplication().statusBarFrame.size.height
let navBarHeight = FolioReader.sharedInstance.readerCenter.navigationController?.navigationBar.frame.size.height
let navTotal = statusbarHeight + navBarHeight!
let newFrame = CGRect(
x: bounds.origin.x,
y: isVerticalDirection(bounds.origin.y + navTotal, bounds.origin.y + navTotal + paddingTop),
width: bounds.width,
height: isVerticalDirection(bounds.height - navTotal, bounds.height - navTotal - paddingTop - paddingBottom))
return newFrame
}

let newFrame = CGRect(
x: bounds.origin.x,
y: isVerticalDirection(bounds.origin.y, bounds.origin.y + paddingTop),
@@ -620,11 +625,15 @@ extension UIWebView {
paginationMode = .LeftToRight
paginationBreakingMode = .Page
scrollView.bounces = false
} else {
} else if readerConfig.scrollDirection == .vertical {
scrollView.pagingEnabled = false
paginationMode = .Unpaginated
scrollView.bounces = true
}
} else {
// swipe paragraphs horizontal, read content vertical
scrollView.bounces = true
self.scrollView.showsVerticalScrollIndicator = true
}
}
}