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

Commit

Permalink
Jumps to the current chapter when opening chapter list (#383)
Browse files Browse the repository at this point in the history
* feat: jump to the current chapter when opening chapter list

* refactor: update indents
  • Loading branch information
camanjj authored and hebertialmeida committed Aug 12, 2019
1 parent 0e9135d commit 3139fdf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Source/FolioReaderChapterList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ class FolioReaderChapterList: UITableViewController {

// Create TOC list
self.tocItems = self.book.flatTableOfContents

// Jump to the current chapter
DispatchQueue.main.async {

if
let currentPageNumber = self.folioReader.readerCenter?.currentPageNumber,
let reference = self.book.spine.spineReferences[safe: currentPageNumber - 1],
let index = self.tocItems.firstIndex(where: { $0.resource == reference.resource }) {

let indexPath = IndexPath(row: index, section: 0)
self.tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
}
}
}

// MARK: - Table view data source
Expand All @@ -72,7 +85,7 @@ class FolioReaderChapterList: UITableViewController {
let cell = tableView.dequeueReusableCell(withIdentifier: kReuseCellIdentifier, for: indexPath) as! FolioReaderChapterListCell

cell.setup(withConfiguration: self.readerConfig)
let tocReference = tocItems[(indexPath as NSIndexPath).row]
let tocReference = tocItems[indexPath.row]
let isSection = tocReference.children.count > 0

cell.indexLabel?.text = tocReference.title.trimmingCharacters(in: .whitespacesAndNewlines)
Expand Down

0 comments on commit 3139fdf

Please sign in to comment.