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

Commit

Permalink
Fixed getCurrentChapter(), not returning some chapters, closes #302 t…
Browse files Browse the repository at this point in the history
…hanks to @wesleycgs
  • Loading branch information
hebertialmeida committed Mar 5, 2018
1 parent a73633b commit 1f96ad4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Source/FolioReaderCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -959,15 +959,23 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl
Find and return the current chapter resource.
*/
public func getCurrentChapter() -> FRResource? {
for item in self.book.flatTableOfContents {
if
let reference = self.book.spine.spineReferences[safe: (self.currentPageNumber - 1)],
let resource = item.resource,
(resource == reference.resource) {
return item.resource
var foundResource: FRResource?

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

if let reference = book.spine.spineReferences[safe: (currentPageNumber - 1)], let resource = item.resource, resource == reference.resource {
foundResource = resource
break
} else if let children = item.children, children.isEmpty == false {
search(children)
}
}
}
return nil
search(book.flatTableOfContents)

return foundResource
}

/**
Expand Down

0 comments on commit 1f96ad4

Please sign in to comment.