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

Commit

Permalink
FolioReaderCenter.getCurrentChapterName() issue, applied recursive se…
Browse files Browse the repository at this point in the history
…arch for toc reference. (#342)

* Fixed FolioReaderWebView, menu controller still showing colors menu after select any color in menu.
https://github.com/FolioReader/FolioReaderKit/issues/316

* Fixed get chapter name method, applied recursive search for toc reference.

* Fix iOS 11 auto adjust inset bug and closes #332 #312 #261 (reverted from commit 0f161dd)

* Fixed FolioReaderWebView, menu controller still showing colors menu after select any color in menu.
https://github.com/FolioReader/FolioReaderKit/issues/316 (reverted from commit b8cccd7)

* Fixed get chapter name method, applied recursive search for toc reference. (reverted from commit 4577d99)

* Fixed get chapter name method, applied recursive search for toc reference. (reverted from commit 4577d99) (reverted from commit f4e657c)

* Fix iOS 11 auto adjust inset bug and closes #332 #312 #261 (unreverted from commit 525b9b5)
  • Loading branch information
wesleycgs authored and hebertialmeida committed Jul 12, 2018
1 parent ae6d67c commit 4742907
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Source/FolioReaderCenter.swift
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
collectionView.decelerationRate = UIScrollViewDecelerationRateFast
enableScrollBetweenChapters(scrollEnabled: true)
view.addSubview(collectionView)

if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
Expand Down Expand Up @@ -1000,19 +1000,25 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
Find and return the current chapter name.
*/
public func getCurrentChapterName() -> String? {
for item in self.book.flatTableOfContents {
guard
let reference = self.book.spine.spineReferences[safe: (self.currentPageNumber - 1)],
let resource = item.resource,
(resource == reference.resource),
let title = item.title else {
continue
var foundChapterName: String?

func search(_ items: [FRTocReference]) {
for item in items {
guard foundChapterName == nil else { break }

if let reference = self.book.spine.spineReferences[safe: (self.currentPageNumber - 1)],
let resource = item.resource,
resource == reference.resource,
let title = item.title {
foundChapterName = title
} else if let children = item.children, children.isEmpty == false {
search(children)
}
}

return title
}

return nil
search(self.book.flatTableOfContents)

return foundChapterName
}

// MARK: Public page methods
Expand Down

0 comments on commit 4742907

Please sign in to comment.