From 7bfc79986b57501986c94348ba96fd36e35953ee Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Fri, 9 Dec 2016 14:43:29 +0200 Subject: [PATCH] Fixed code style Extracted duplicate "hack" into a clearly named function. Previously, not all instances had the explanation comment, and its side effect was not clear. --- Source/FolioReaderWebView.swift | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Source/FolioReaderWebView.swift b/Source/FolioReaderWebView.swift index 211d0113e..5505857a1 100644 --- a/Source/FolioReaderWebView.swift +++ b/Source/FolioReaderWebView.swift @@ -50,8 +50,8 @@ open class FolioReaderWebView: UIWebView { } else { if let textToShare = self.js("getSelectedText()") { FolioReader.shared.readerCenter?.presentQuoteShare(textToShare) - self.isUserInteractionEnabled = false - self.isUserInteractionEnabled = true + + self.clearTextSelection() } } self.setMenuVisible(false) @@ -108,9 +108,7 @@ open class FolioReaderWebView: UIWebView { let startOffset = dic["startOffset"]! let endOffset = dic["endOffset"]! - // Force remove text selection - isUserInteractionEnabled = false - isUserInteractionEnabled = true + self.clearTextSelection() createMenu(options: true) setMenuVisible(true, andRect: rect) @@ -129,8 +127,8 @@ open class FolioReaderWebView: UIWebView { let selectedText = js("getSelectedText()") setMenuVisible(false) - isUserInteractionEnabled = false - isUserInteractionEnabled = true + + self.clearTextSelection() let vc = UIReferenceLibraryViewController(term: selectedText! ) vc.view.tintColor = readerConfig.tintColor @@ -140,10 +138,7 @@ open class FolioReaderWebView: UIWebView { func play(_ sender: UIMenuController?) { FolioReader.shared.readerAudioPlayer?.play() - // Force remove text selection - // @NOTE: this doesn't seem to always work - isUserInteractionEnabled = false - isUserInteractionEnabled = true + self.clearTextSelection() } func setYellow(_ sender: UIMenuController?) { @@ -273,7 +268,15 @@ open class FolioReaderWebView: UIWebView { return callback } - // MARK: WebView direction config + // MARK: WebView + + func clearTextSelection() { + // Forces text selection clearing + // @NOTE: this doesn't seem to always work + + self.isUserInteractionEnabled = false + self.isUserInteractionEnabled = true + } func setupScrollDirection() { switch readerConfig.scrollDirection {