Reorganize docs and update reader search flows
This commit is contained in:
@@ -53,6 +53,7 @@ public final class RDURLReaderController: UIViewController {
|
||||
private let pendingDemoPageRetryDelay: TimeInterval = 0.25
|
||||
private var demoStateTimer: Timer?
|
||||
private var lastEmittedDemoState = ""
|
||||
private var pendingSearchKeyword: String?
|
||||
|
||||
/// 初始化方法
|
||||
/// - Parameters:
|
||||
@@ -147,18 +148,41 @@ public final class RDURLReaderController: UIViewController {
|
||||
}
|
||||
|
||||
/// 执行搜索(Demo 用)
|
||||
/// 显示搜索栏并提交关键词
|
||||
/// 显示搜索栏并提交关键词。若阅读器尚未完成加载则延迟到 `didUpdateLocation` 后执行。
|
||||
/// - Parameter keyword: 搜索关键词
|
||||
public func performDemoSearch(keyword: String) {
|
||||
guard let readerController else { return }
|
||||
readerController.showSearchBar()
|
||||
// 等搜索栏动画完成后提交搜索
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
if readerController.parser != nil || readerController.textBook != nil {
|
||||
submitSearchAfterDelay(keyword: keyword, retries: 5)
|
||||
} else {
|
||||
pendingSearchKeyword = keyword
|
||||
}
|
||||
}
|
||||
|
||||
private func submitSearchAfterDelay(keyword: String, retries: Int = 0) {
|
||||
guard let readerController else { return }
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
|
||||
guard let self else { return }
|
||||
readerController.search(keyword: keyword)
|
||||
readerController.updateSearchCount()
|
||||
if retries > 0,
|
||||
readerController.searchState?.matches.isEmpty != false,
|
||||
readerController.parser == nil {
|
||||
self.submitSearchAfterDelay(keyword: keyword, retries: retries - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func executePendingSearchIfNeeded() {
|
||||
guard let keyword = pendingSearchKeyword else { return }
|
||||
guard let readerController, readerController.parser != nil || readerController.textBook != nil else {
|
||||
return
|
||||
}
|
||||
pendingSearchKeyword = nil
|
||||
submitSearchAfterDelay(keyword: keyword, retries: 5)
|
||||
}
|
||||
|
||||
/// 嵌入阅读器控制器到当前视图层级
|
||||
/// 根据文件类型选择合适的阅读器控制器,并通过 Child View Controller 方式嵌入
|
||||
private func embedReaderController() {
|
||||
@@ -339,6 +363,7 @@ public final class RDURLReaderController: UIViewController {
|
||||
let display = readerController?.configuration.displayType.demoArgumentValue ?? epubConfiguration.displayType.demoArgumentValue
|
||||
let toolbar = readerController?.readerView.isShowToolView == true ? "visible" : "hidden"
|
||||
let highlights = readerController?.highlights.count ?? 0
|
||||
let bookmarks = readerController?.activeBookmarks.count ?? 0
|
||||
let selection = readerController?.currentSelection == nil ? 0 : 1
|
||||
let location = readerController?.currentLocation
|
||||
let href = encodedDemoLocationHref(location?.href)
|
||||
@@ -351,6 +376,7 @@ public final class RDURLReaderController: UIViewController {
|
||||
"display=\(display)",
|
||||
"toolbar=\(toolbar)",
|
||||
"highlights=\(highlights)",
|
||||
"bookmarks=\(bookmarks)",
|
||||
"selection=\(selection)",
|
||||
"href=\(href)",
|
||||
"progression=\(progression)",
|
||||
@@ -439,11 +465,13 @@ public final class RDURLReaderController: UIViewController {
|
||||
extension RDURLReaderController: RDEPUBReaderDelegate {
|
||||
public func epubReader(_ reader: UIViewController, didOpen publication: RDEPUBPublication) {
|
||||
retryPendingDemoPageIfNeeded()
|
||||
executePendingSearchIfNeeded()
|
||||
emitDemoState()
|
||||
}
|
||||
|
||||
public func epubReader(_ reader: UIViewController, didUpdateLocation location: RDEPUBLocation) {
|
||||
retryPendingDemoPageIfNeeded()
|
||||
executePendingSearchIfNeeded()
|
||||
emitDemoState()
|
||||
}
|
||||
|
||||
@@ -454,6 +482,10 @@ extension RDURLReaderController: RDEPUBReaderDelegate {
|
||||
public func epubReader(_ reader: UIViewController, didUpdateHighlights highlights: [RDEPUBHighlight]) {
|
||||
emitDemoState(prefix: "highlights=\(highlights.count)")
|
||||
}
|
||||
|
||||
public func epubReader(_ reader: UIViewController, didUpdateBookmarks bookmarks: [RDEPUBBookmark]) {
|
||||
emitDemoState(prefix: "bookmarks=\(bookmarks.count)")
|
||||
}
|
||||
}
|
||||
|
||||
/// 翻页模式扩展:提供 Demo 命令行参数值
|
||||
|
||||
Reference in New Issue
Block a user