Manos Chorianopoulos

Add merchant description to CouponBarcodeVC

......@@ -10,7 +10,7 @@ import UIKit
import AVFoundation
// import SwiftEventBus
@objc public class CouponBarcodeViewController: UIViewController {
@objc public class CouponBarcodeViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var mainView: UIView!
@IBOutlet weak var backgroundImage: UIImageView!
@IBOutlet weak var scrollView: UIScrollView!
......@@ -19,6 +19,9 @@ import AVFoundation
@IBOutlet weak var couponImageHeight: NSLayoutConstraint!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var discriptionLabel: UILabel!
@IBOutlet weak var merchantDescrTextView: UnselectableTappableTextView!
@IBOutlet weak var merchantDescrTextViewHeight: NSLayoutConstraint!
@IBOutlet weak var merchantDescrTextViewTopSpace: NSLayoutConstraint!
@IBOutlet weak var couponView: UIView!
@IBOutlet weak var couponNumberLabel: CopyableLabel!
@IBOutlet weak var barcodeImage: UIImageView!
......@@ -29,7 +32,7 @@ import AVFoundation
@IBOutlet weak var expirationLabel: UILabel!
@IBOutlet weak var redeemButton: UIButton!
@IBOutlet weak var termsButton: UIButton!
@IBOutlet weak var termsTextView: UITextView!
@IBOutlet weak var termsTextView: UnselectableTappableTextView!
@IBOutlet weak var termsTextViewHeight: NSLayoutConstraint!
@IBOutlet weak var borderViewHeight: NSLayoutConstraint!
@IBOutlet weak var borderView2Height: NSLayoutConstraint!
......@@ -60,6 +63,8 @@ import AVFoundation
super.viewDidLoad()
self.hidesBottomBarWhenPushed = true
merchantDescrTextView.delegate = self
termsTextView.delegate = self
// Do any additional setup after loading the view.
setBackButton()
......@@ -101,6 +106,38 @@ import AVFoundation
nameLabel.text = couponSetData?.name ?? ""
discriptionLabel.text = couponSetData?.short_description ?? ""
merchantDescrTextView.text = ""
merchantDescrTextViewTopSpace.constant = CGFloat(0)
merchantDescrTextViewHeight.constant = CGFloat(0)
merchantDescrTextView.isHidden = true
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
for merchant in merchantList {
if (merchant._uuid == couponSetData?.merchant_uuid) {
let htmlMerchDescrText = merchant._body
if (htmlMerchDescrText != "") {
merchantDescrTextView.attributedText = htmlMerchDescrText.htmlToAttributedString
merchantDescrTextView.font = UIFont(name: "PFSquareSansPro-Regular", size: 17)
merchantDescrTextView.textColor = UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00)
merchantDescrTextView.textAlignment = .center
merchantDescrTextView.isScrollEnabled = false
merchantDescrTextView.isUserInteractionEnabled = true
merchantDescrTextView.isEditable = false
merchantDescrTextView.isSelectable = true
merchantDescrTextView.dataDetectorTypes = [.link]
merchantDescrTextView.isHidden = false
merchantDescrTextViewTopSpace.constant = CGFloat(15)
let targetSize = CGSize(width: merchantDescrTextView.frame.width, height: CGFloat(MAXFLOAT))
merchantDescrTextViewHeight.constant = merchantDescrTextView.sizeThatFits(targetSize).height
}
break;
}
}
couponView.layer.cornerRadius = 8
couponNumberLabel.text = coupon?.coupon ?? ""
couponView.frame = CGRect(x: 0.0, y: 0.0, width: couponView.intrinsicContentSize.width, height: 55)
......@@ -246,6 +283,11 @@ import AVFoundation
termsTextView.textAlignment = .center
termsTextView.isScrollEnabled = false
termsTextView.isUserInteractionEnabled = true
termsTextView.isEditable = false
termsTextView.isSelectable = true
termsTextView.dataDetectorTypes = [.link]
// Uncomment if Barcode Section is active again
// toggleTerms()
toggleBarcode()
......@@ -265,6 +307,14 @@ import AVFoundation
}
public func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
UIApplication.shared.open(URL)
// Disable `.preview` by 3D Touch and other interactions
return false
}
// MARK: - Functions
func toggleTerms() {
if (termsVisible) {
......
......@@ -490,3 +490,35 @@ extension UINavigationController {
return nil
}
}
/// Class to allow links but no selection.
/// Basically, it disables unwanted UIGestureRecognizer from UITextView.
class UnselectableTappableTextView: UITextView {
// required to prevent blue background selection from any situation
override var selectedTextRange: UITextRange? {
get { return nil }
set {}
}
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer is UIPanGestureRecognizer {
// required for compatibility with isScrollEnabled
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
if let tapGestureRecognizer = gestureRecognizer as? UITapGestureRecognizer,
tapGestureRecognizer.numberOfTapsRequired == 1 {
// required for compatibility with links
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
// allowing smallDelayRecognizer for links
if let longPressGestureRecognizer = gestureRecognizer as? UILongPressGestureRecognizer,
// comparison value is used to distinguish between 0.12 (smallDelayRecognizer) and 0.5 (textSelectionForce and textLoupe)
longPressGestureRecognizer.minimumPressDuration < 0.325 {
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
// preventing selection from loupe/magnifier (_UITextSelectionForceGesture), multi tap, tap and a half, etc.
gestureRecognizer.isEnabled = false
return false
}
}
......