This repository was archived by the owner on Nov 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 790
Migration/wkwebview #388
Draft
Draft
Migration/wkwebview #388
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cbe3dab
Started migration to the WKWebView
OrbitalMan dd793fc
fixed JavaScript evaluations by making them asynchronous
OrbitalMan 325ad88
injecting javascript code the WebKit way
OrbitalMan 767c88d
fixed pages counter calculations
OrbitalMan 49076e4
fixed FolioReaderPage reference
OrbitalMan 8226e55
updated viewport tag injection
OrbitalMan 36bf1f0
updated css and javascript injection
OrbitalMan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
Example/Podfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| platform :ios, '9.0' | ||
| platform :ios, '10.0' | ||
|
|
||
| use_frameworks! | ||
| inhibit_all_warnings! | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| import UIKit | ||
| import ZFDragableModalTransition | ||
| import WebKit | ||
|
|
||
| /// Protocol which is used from `FolioReaderCenter`s. | ||
| @objc public protocol FolioReaderCenterDelegate: class { | ||
|
|
@@ -464,17 +465,11 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl | |
| guard var html = try? String(contentsOfFile: resource.fullHref, encoding: String.Encoding.utf8) else { | ||
| return cell | ||
| } | ||
|
|
||
| // Inject viewport | ||
| let viewportTag = "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, shrink-to-fit=no\">" | ||
|
|
||
| let mediaOverlayStyleColors = "\"\(self.readerConfig.mediaOverlayColor.hexString(false))\", \"\(self.readerConfig.mediaOverlayColor.highlightColor().hexString(false))\"" | ||
|
|
||
| // Inject CSS | ||
| let jsFilePath = Bundle.frameworkBundle().path(forResource: "Bridge", ofType: "js") | ||
| let cssFilePath = Bundle.frameworkBundle().path(forResource: "Style", ofType: "css") | ||
| let cssTag = "<link rel=\"stylesheet\" type=\"text/css\" href=\"\(cssFilePath!)\">" | ||
| let jsTag = "<script type=\"text/javascript\" src=\"\(jsFilePath!)\"></script>" + | ||
| "<script type=\"text/javascript\">setMediaOverlayStyleColors(\(mediaOverlayStyleColors))</script>" | ||
|
|
||
| let toInject = "\n\(cssTag)\n\(jsTag)\n</head>" | ||
| let toInject = "\n\(viewportTag)\n</head>" | ||
| html = html.replacingOccurrences(of: "</head>", with: toInject) | ||
|
|
||
| // Font class name | ||
|
|
@@ -648,18 +643,13 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl | |
| } | ||
|
|
||
| scrollScrubber?.setSliderVal() | ||
|
|
||
| if let readingTime = currentPage.webView?.js("getReadingTime()") { | ||
| pageIndicatorView?.totalMinutes = Int(readingTime)! | ||
| } else { | ||
| pageIndicatorView?.totalMinutes = 0 | ||
| currentPage.webView?.js("getReadingTime()") { readingTime in | ||
| self.pageIndicatorView?.totalMinutes = Int(readingTime ?? "0")! | ||
| self.pagesForCurrentPage(currentPage) | ||
| self.delegate?.pageDidAppear?(currentPage) | ||
| self.delegate?.pageItemChanged?(self.getCurrentPageItemNumber()) | ||
| completion?() | ||
| } | ||
| pagesForCurrentPage(currentPage) | ||
|
|
||
| delegate?.pageDidAppear?(currentPage) | ||
| delegate?.pageItemChanged?(self.getCurrentPageItemNumber()) | ||
|
|
||
| completion?() | ||
| } | ||
|
|
||
| func pagesForCurrentPage(_ page: FolioReaderPage?) { | ||
|
|
@@ -1075,9 +1065,10 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl | |
| @objc func shareChapter(_ sender: UIBarButtonItem) { | ||
| guard let currentPage = currentPage else { return } | ||
|
|
||
| if let chapterText = currentPage.webView?.js("getBodyText()") { | ||
| currentPage.webView?.js("getBodyText()") { chapterText in | ||
| guard let chapterText = chapterText else { return } | ||
| let htmlText = chapterText.replacingOccurrences(of: "[\\n\\r]+", with: "<br />", options: .regularExpression) | ||
| var subject = readerConfig.localizedShareChapterSubject | ||
| var subject = self.readerConfig.localizedShareChapterSubject | ||
| var html = "" | ||
| var text = "" | ||
| var bookTitle = "" | ||
|
|
@@ -1092,7 +1083,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl | |
| } | ||
|
|
||
| // Get chapter name | ||
| if let chapter = getCurrentChapterName() { | ||
| if let chapter = self.getCurrentChapterName() { | ||
| chapterName = chapter | ||
| } | ||
|
|
||
|
|
@@ -1104,17 +1095,17 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl | |
| // Sharing html and text | ||
| html = "<html><body>" | ||
| html += "<br /><hr> <p>\(htmlText)</p> <hr><br />" | ||
| html += "<center><p style=\"color:gray\">"+readerConfig.localizedShareAllExcerptsFrom+"</p>" | ||
| html += "<center><p style=\"color:gray\">"+self.readerConfig.localizedShareAllExcerptsFrom+"</p>" | ||
| html += "<b>\(bookTitle)</b><br />" | ||
| html += readerConfig.localizedShareBy+" <i>\(authorName)</i><br />" | ||
|
|
||
| if let bookShareLink = readerConfig.localizedShareWebLink { | ||
| html += self.readerConfig.localizedShareBy+" <i>\(authorName)</i><br />" | ||
| if let bookShareLink = self.readerConfig.localizedShareWebLink { | ||
| html += "<a href=\"\(bookShareLink.absoluteString)\">\(bookShareLink.absoluteString)</a>" | ||
| shareItems.append(bookShareLink as AnyObject) | ||
| } | ||
|
|
||
| html += "</center></body></html>" | ||
| text = "\(chapterName)\n\n"\(chapterText)" \n\n\(bookTitle) \n\(readerConfig.localizedShareBy) \(authorName)" | ||
| text = "\(chapterName)\n\n"\(chapterText)" \n\n\(bookTitle) \n\(self.readerConfig.localizedShareBy) \(authorName)" | ||
|
|
||
| let act = FolioReaderSharingProvider(subject: subject, text: text, html: html) | ||
| shareItems.insert(contentsOf: [act, "" as AnyObject], at: 0) | ||
|
|
@@ -1127,7 +1118,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl | |
| actv.barButtonItem = sender | ||
| } | ||
|
|
||
| present(activityViewController, animated: true, completion: nil) | ||
| self.present(activityViewController, animated: true, completion: nil) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1281,7 +1272,7 @@ open class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UIColl | |
| // Perform the page after a short delay as the collection view hasn't completed it's transition if this method is called (the index paths aren't right during fast scrolls). | ||
| delay(0.2, closure: { [weak self] in | ||
| if (self?.readerConfig.scrollDirection == .horizontalWithVerticalContent), | ||
| let cell = ((scrollView.superview as? UIWebView)?.delegate as? FolioReaderPage) { | ||
| let cell = ((scrollView.superview as? WKWebView)?.navigationDelegate as? FolioReaderPage) { | ||
| let currentIndexPathRow = cell.pageNumber - 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @ThakarRajesh! I have already fixed the UIWebView reference - please take a look at commit 49076e4 |
||
| self?.currentWebViewScrollPositions[currentIndexPathRow] = scrollView.contentOffset | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.