Commit 11165627 by Daniel Dahan

development: fixed double hit test in Menu that was causing the delegation…

development: fixed double hit test in Menu that was causing the delegation method to be fired more than once
parent 8fbde3d6
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_work_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_work_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_work_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
...@@ -94,7 +94,6 @@ extension CollectionViewController { ...@@ -94,7 +94,6 @@ extension CollectionViewController {
} }
extension CollectionViewController: CollectionViewDelegate {} extension CollectionViewController: CollectionViewDelegate {}
extension CollectionViewController: CollectionViewDataSource { extension CollectionViewController: CollectionViewDataSource {
@objc @objc
open func numberOfSections(in collectionView: UICollectionView) -> Int { open func numberOfSections(in collectionView: UICollectionView) -> Int {
......
...@@ -95,6 +95,7 @@ public struct Icon { ...@@ -95,6 +95,7 @@ public struct Icon {
public static let starHalf = Icon.icon("ic_star_half_white") public static let starHalf = Icon.icon("ic_star_half_white")
public static let videocam = Icon.icon("ic_videocam_white") public static let videocam = Icon.icon("ic_videocam_white")
public static let visibility = Icon.icon("ic_visibility_white") public static let visibility = Icon.icon("ic_visibility_white")
public static let work = Icon.icon("ic_work_white")
/// CosmicMind icons. /// CosmicMind icons.
public struct cm { public struct cm {
......
...@@ -110,7 +110,7 @@ extension UIView { ...@@ -110,7 +110,7 @@ extension UIView {
} }
} }
/// Grid reference. /// Depth reference.
open var depth: Depth { open var depth: Depth {
get { get {
return layer.depth return layer.depth
......
...@@ -49,7 +49,9 @@ extension UIViewController { ...@@ -49,7 +49,9 @@ extension UIViewController {
} }
open class MenuController: RootController { open class MenuController: RootController {
/// Reference to the MenuView. open fileprivate(set) var blurView: UIView?
/// Reference to the MenuView.
@IBInspectable @IBInspectable
open let menu = Menu() open let menu = Menu()
...@@ -88,12 +90,21 @@ extension MenuController { ...@@ -88,12 +90,21 @@ extension MenuController {
open func openMenu(completion: ((UIView) -> Void)? = nil) { open func openMenu(completion: ((UIView) -> Void)? = nil) {
if true == isUserInteractionEnabled { if true == isUserInteractionEnabled {
isUserInteractionEnabled = false isUserInteractionEnabled = false
UIView.animate(withDuration: 0.15, animations: { [weak self] in
guard let s = self else { if nil == blurView {
return let blur = UIVisualEffectView(effect: UIBlurEffect(style: .light))
} blurView = UIView()
s.rootViewController.view.alpha = 0.15 blurView?.layout(blur).edges()
}) view.layout(blurView!).edges()
view.bringSubview(toFront: menu)
}
// UIView.animate(withDuration: 0.15, animations: { [weak self] in
// guard let s = self else {
// return
// }
// s.rootViewController.view.alpha = 0.15
// })
menu.open { [completion = completion] (view) in menu.open { [completion = completion] (view) in
completion?(view) completion?(view)
} }
...@@ -107,12 +118,16 @@ extension MenuController { ...@@ -107,12 +118,16 @@ extension MenuController {
*/ */
open func closeMenu(completion: ((UIView) -> Void)? = nil) { open func closeMenu(completion: ((UIView) -> Void)? = nil) {
if false == isUserInteractionEnabled { if false == isUserInteractionEnabled {
UIView.animate(withDuration: 0.15, animations: { [weak self] in blurView?.removeFromSuperview()
guard let s = self else { blurView = nil
return
}
s.rootViewController.view.alpha = 1 // UIView.animate(withDuration: 0.15, animations: { [weak self] in
}) // guard let s = self else {
// return
// }
// s.rootViewController.view.alpha = 1
// })
menu.close { [weak self] (view) in menu.close { [weak self] (view) in
guard let s = self else { guard let s = self else {
return return
......
...@@ -124,16 +124,6 @@ open class SearchBar: Bar { ...@@ -124,16 +124,6 @@ open class SearchBar: Bar {
} }
} }
open override func layoutSubviews() {
super.layoutSubviews()
guard willLayout else {
return
}
textField.frame = contentView.bounds
layoutClearButton()
}
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
...@@ -152,6 +142,17 @@ open class SearchBar: Bar { ...@@ -152,6 +142,17 @@ open class SearchBar: Bar {
super.init(frame: frame) super.init(frame: frame)
} }
open override func layoutSubviews() {
super.layoutSubviews()
guard willLayout else {
return
}
textField.frame = contentView.bounds
layoutLeftView()
layoutClearButton()
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method it is recommended to override the prepare method
...@@ -164,16 +165,32 @@ open class SearchBar: Bar { ...@@ -164,16 +165,32 @@ open class SearchBar: Bar {
prepareTextField() prepareTextField()
prepareClearButton() prepareClearButton()
} }
}
/// Layout the clearButton.
open func layoutClearButton() { extension SearchBar {
let h = textField.frame.height /// Layout the clearButton.
clearButton.frame = CGRect(x: textField.frame.width - h, y: 0, width: h, height: h) open func layoutClearButton() {
} let h = textField.frame.height
clearButton.frame = CGRect(x: textField.frame.width - h - 4, y: 4, width: h, height: h - 8)
/// Clears the textField text. }
@objc
internal func handleClearButton() { /// Layout the leftView.
open func layoutLeftView() {
guard let v = textField.leftView else {
return
}
let h = textField.frame.height
v.frame = CGRect(x: 4, y: 4, width: h, height: h - 8)
(v as? UIImageView)?.contentMode = .scaleAspectFit
}
}
extension SearchBar {
/// Clears the textField text.
@objc
fileprivate func handleClearButton() {
guard nil == textField.delegate?.textFieldShouldClear || true == textField.delegate?.textFieldShouldClear?(textField) else { guard nil == textField.delegate?.textFieldShouldClear || true == textField.delegate?.textFieldShouldClear?(textField) else {
return return
} }
...@@ -186,33 +203,35 @@ open class SearchBar: Bar { ...@@ -186,33 +203,35 @@ open class SearchBar: Bar {
delegate?.searchBar?(searchBar: self, didClear: textField, with: t) delegate?.searchBar?(searchBar: self, didClear: textField, with: t)
} }
// Live updates the search results. // Live updates the search results.
@objc @objc
internal func handleEditingChanged(textField: UITextField) { fileprivate func handleEditingChanged(textField: UITextField) {
delegate?.searchBar?(searchBar: self, didChange: textField, with: textField.text) delegate?.searchBar?(searchBar: self, didChange: textField, with: textField.text)
} }
}
/// Prepares the textField.
private func prepareTextField() { extension SearchBar {
textField.contentScaleFactor = Screen.scale /// Prepares the textField.
textField.font = RobotoFont.regular(with: 17) fileprivate func prepareTextField() {
textField.backgroundColor = Color.clear textField.contentScaleFactor = Screen.scale
textField.clearButtonMode = .whileEditing textField.font = RobotoFont.regular(with: 17)
tintColor = placeholderColor textField.backgroundColor = Color.clear
textColor = Color.darkText.primary textField.clearButtonMode = .whileEditing
placeholder = "Search" tintColor = placeholderColor
contentView.addSubview(textField) textColor = Color.darkText.primary
placeholder = "Search"
contentView.addSubview(textField)
textField.addTarget(self, action: #selector(handleEditingChanged(textField:)), for: .editingChanged) textField.addTarget(self, action: #selector(handleEditingChanged(textField:)), for: .editingChanged)
} }
/// Prepares the clearButton. /// Prepares the clearButton.
private func prepareClearButton() { fileprivate func prepareClearButton() {
clearButton = IconButton(image: Icon.cm.close, tintColor: placeholderColor) clearButton = IconButton(image: Icon.cm.close, tintColor: placeholderColor)
clearButton.contentEdgeInsets = .zero clearButton.contentEdgeInsets = .zero
isClearButtonAutoHandleEnabled = true isClearButtonAutoHandleEnabled = true
textField.clearButtonMode = .never textField.clearButtonMode = .never
textField.rightViewMode = .whileEditing textField.rightViewMode = .whileEditing
textField.rightView = clearButton textField.rightView = clearButton
} }
} }
...@@ -59,14 +59,6 @@ open class Snackbar: Bar { ...@@ -59,14 +59,6 @@ open class Snackbar: Bar {
open internal(set) var status = SnackbarStatus.hidden open internal(set) var status = SnackbarStatus.hidden
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
/**
Since the subviews will be outside the bounds of this view,
we need to look at the subviews to see if we have a hit.
*/
guard !isHidden else {
return nil
}
for v in subviews { for v in subviews {
let p = v.convert(point, from: self) let p = v.convert(point, from: self)
if v.bounds.contains(p) { if v.bounds.contains(p) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment