added iOS source code
[wl-app.git] / iOS / Pods / SideMenu / Pod / Classes / UITableViewVibrantCell.swift
diff --git a/iOS/Pods/SideMenu/Pod/Classes/UITableViewVibrantCell.swift b/iOS/Pods/SideMenu/Pod/Classes/UITableViewVibrantCell.swift
new file mode 100644 (file)
index 0000000..2ececb7
--- /dev/null
@@ -0,0 +1,61 @@
+//
+//  UITableViewVibrantCell.swift
+//  Pods
+//
+//  Created by Jon Kent on 1/14/16.
+//
+//
+
+import UIKit
+
+open class UITableViewVibrantCell: UITableViewCell {
+    
+    fileprivate var vibrancyView:UIVisualEffectView = UIVisualEffectView()
+    fileprivate var vibrancySelectedBackgroundView:UIVisualEffectView = UIVisualEffectView()
+    fileprivate var defaultSelectedBackgroundView:UIView?
+    open var blurEffectStyle: UIBlurEffectStyle? {
+        didSet {
+            updateBlur()
+        }
+    }
+    
+    // For registering with UITableView without subclassing otherwise dequeuing instance of the cell causes an exception
+    public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
+        super.init(style: style, reuseIdentifier: reuseIdentifier)
+    }
+    
+    required public init?(coder aDecoder: NSCoder) {
+        super.init(coder: aDecoder)
+        
+        vibrancyView.frame = bounds
+        vibrancyView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
+        for view in subviews {
+            vibrancyView.contentView.addSubview(view)
+        }
+        addSubview(vibrancyView)
+        
+        let blurSelectionEffect = UIBlurEffect(style: .light)
+        vibrancySelectedBackgroundView.effect = blurSelectionEffect
+        defaultSelectedBackgroundView = selectedBackgroundView
+        
+        updateBlur()
+    }
+    
+    internal func updateBlur() {
+        // shouldn't be needed but backgroundColor is set to white on iPad:
+        backgroundColor = UIColor.clear
+        
+        if let blurEffectStyle = blurEffectStyle, !UIAccessibilityIsReduceTransparencyEnabled() {
+            let blurEffect = UIBlurEffect(style: blurEffectStyle)
+            vibrancyView.effect = UIVibrancyEffect(blurEffect: blurEffect)
+            
+            if selectedBackgroundView != nil && selectedBackgroundView != vibrancySelectedBackgroundView {
+                vibrancySelectedBackgroundView.contentView.addSubview(selectedBackgroundView!)
+                selectedBackgroundView = vibrancySelectedBackgroundView
+            }
+        } else {
+            vibrancyView.effect = nil
+            selectedBackgroundView = defaultSelectedBackgroundView
+        }
+    }
+}