Conversation
- provide the ability add custom native overlay to EPUB resources - possible to render any type wrapped inside XHTML spine element (e.g. PDF)
| In order for this method to be invoked for given resource/spine element must have ```properties``` attribute configured with appropriate metadata needed to able to render custom spread. | ||
|
|
||
| ```html | ||
| <item id="item-page-1" href="001-chapter.xhtml" media-type="application/xhtml+xml properties="document:pages/pg-1605839.pdf custom-type:pdf"/> |
There was a problem hiding this comment.
We can discuss how we could name properties used to describe custom type.
| let spread = spreads[index] | ||
|
|
||
| let linksForSpread: [Link] = spread.readingOrderIndices.map { index in | ||
| publication.readingOrder[index] |
There was a problem hiding this comment.
If I'm not mistaken, publication.readingOrder is an array, right? If so, you might want to use safe index here.
| let isCustom = linksForSpread.contains(where: { $0.properties.renderOptions != nil }) | ||
|
|
||
| if isCustom, let customView = delegate?.navigator(self, viewForReadingOrderLinks: linksForSpread) { | ||
| let customTypeSpreadContainer = CustomTypeSpreadViewWrapper(spread: spread) |
There was a problem hiding this comment.
Could you separate all this logic into a new createCustomTypeSpreadContainer function?
| } | ||
| let isCustom = linksForSpread.contains(where: { $0.properties.renderOptions != nil }) | ||
|
|
||
| if isCustom, let customView = delegate?.navigator(self, viewForReadingOrderLinks: linksForSpread) { |
There was a problem hiding this comment.
Why customView and not customViewController?
| ]) | ||
|
|
||
| // handle case when only one page in spread is custom view | ||
| if linksForSpread.count == 2 { |
There was a problem hiding this comment.
I assume you are counting on the preconditions defined here: https://github.com/readium/swift-toolkit/blob/develop/Sources/Navigator/EPUB/EPUBSpread.swift#L27
However, did you see this comment: https://github.com/readium/swift-toolkit/blob/develop/Sources/Navigator/EPUB/EPUBSpread.swift#L18
Does this fit into your initial idea? I find this hard to understand without digging deeper into the SDK implementation...
|
|
||
| func navigator(_ navigator: EPUBNavigatorViewController, setupUserScripts userContentController: WKUserContentController) | ||
|
|
||
| func navigator(_ navigator: EPUBNavigatorViewController, viewForReadingOrderLinks links: [Link]) -> UIViewController? |
There was a problem hiding this comment.
func navigator(_ navigator: EPUBNavigatorViewController, viewControllerForReadingOrderLinks links: [Link]) -> UIViewController? 👍
| private func parseStringProperties(_ properties: [String]) -> [String: Any] { | ||
| var contains: [String] = [] | ||
| var page: Properties.Page? | ||
| var renderCustom: [String: Any] = [:] |
There was a problem hiding this comment.
keyValueProperties seems like a more descriptive name.
| import UIKit | ||
| import WebKit | ||
|
|
||
| public extension Properties { |
There was a problem hiding this comment.
What about renaming RenderMetadata to CustomViewMetadata and renderOptions to customViewMetadata?
…r-custom-spread-pages
EPUBNavigatorDelegate
Readium allows rendering EPUB spine elements in a custom way (e.g. PDF is rendered using PDFKit instead of being loaded in WKWebView).
Client can provide custom view for given spread using
delegate method.
Returned tuple contains left and right pages if spread has 2 pages. Center property is used in case spread has 1 page.
In case any of spread pages doesn't require custom view
nilis returned for such page, and readium will fallback to webview rendering.linkscontains array of EPUB spine element links (if spread has 2 pages it will have 2 links, otherwise 1 link).EPUB document could hold JSON resource which contains mapping of spine element links to metadata model needed to perform custom rendering (e.g. asset hrefs, custom view type info ...)