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

Commit

Permalink
Fixed code style (#191)
Browse files Browse the repository at this point in the history
Extracted duplicate "hack" into a clearly named function. Previously, not all
instances had the explanation comment, and its side effect was not clear.
  • Loading branch information
revolter authored and hebertialmeida committed Dec 9, 2016
1 parent 4d1366a commit 3377280
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Source/FolioReaderWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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?) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3377280

Please sign in to comment.