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 {
}
extension CollectionViewController: CollectionViewDelegate {}
extension CollectionViewController: CollectionViewDataSource {
@objc
open func numberOfSections(in collectionView: UICollectionView) -> Int {
......
......@@ -95,6 +95,7 @@ public struct Icon {
public static let starHalf = Icon.icon("ic_star_half_white")
public static let videocam = Icon.icon("ic_videocam_white")
public static let visibility = Icon.icon("ic_visibility_white")
public static let work = Icon.icon("ic_work_white")
/// CosmicMind icons.
public struct cm {
......
......@@ -110,7 +110,7 @@ extension UIView {
}
}
/// Grid reference.
/// Depth reference.
open var depth: Depth {
get {
return layer.depth
......
......@@ -49,7 +49,9 @@ extension UIViewController {
}
open class MenuController: RootController {
/// Reference to the MenuView.
open fileprivate(set) var blurView: UIView?
/// Reference to the MenuView.
@IBInspectable
open let menu = Menu()
......@@ -88,12 +90,21 @@ extension MenuController {
open func openMenu(completion: ((UIView) -> Void)? = nil) {
if true == isUserInteractionEnabled {
isUserInteractionEnabled = false
UIView.animate(withDuration: 0.15, animations: { [weak self] in
guard let s = self else {
return
}
s.rootViewController.view.alpha = 0.15
})
if nil == blurView {
let blur = UIVisualEffectView(effect: UIBlurEffect(style: .light))
blurView = UIView()
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
completion?(view)
}
......@@ -107,12 +118,16 @@ extension MenuController {
*/
open func closeMenu(completion: ((UIView) -> Void)? = nil) {
if false == isUserInteractionEnabled {
UIView.animate(withDuration: 0.15, animations: { [weak self] in
guard let s = self else {
return
}
s.rootViewController.view.alpha = 1
})
blurView?.removeFromSuperview()
blurView = nil
// 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
guard let s = self else {
return
......
......@@ -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.
- Parameter aDecoder: A NSCoder instance.
......@@ -152,6 +142,17 @@ open class SearchBar: Bar {
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,
it is recommended to override the prepare method
......@@ -164,16 +165,32 @@ open class SearchBar: Bar {
prepareTextField()
prepareClearButton()
}
/// Layout the clearButton.
open func layoutClearButton() {
let h = textField.frame.height
clearButton.frame = CGRect(x: textField.frame.width - h, y: 0, width: h, height: h)
}
/// Clears the textField text.
@objc
internal func handleClearButton() {
}
extension SearchBar {
/// Layout the clearButton.
open func layoutClearButton() {
let h = textField.frame.height
clearButton.frame = CGRect(x: textField.frame.width - h - 4, y: 4, width: h, height: h - 8)
}
/// 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 {
return
}
......@@ -186,33 +203,35 @@ open class SearchBar: Bar {
delegate?.searchBar?(searchBar: self, didClear: textField, with: t)
}
// Live updates the search results.
@objc
internal func handleEditingChanged(textField: UITextField) {
fileprivate func handleEditingChanged(textField: UITextField) {
delegate?.searchBar?(searchBar: self, didChange: textField, with: textField.text)
}
/// Prepares the textField.
private func prepareTextField() {
textField.contentScaleFactor = Screen.scale
textField.font = RobotoFont.regular(with: 17)
textField.backgroundColor = Color.clear
textField.clearButtonMode = .whileEditing
tintColor = placeholderColor
textColor = Color.darkText.primary
placeholder = "Search"
contentView.addSubview(textField)
}
extension SearchBar {
/// Prepares the textField.
fileprivate func prepareTextField() {
textField.contentScaleFactor = Screen.scale
textField.font = RobotoFont.regular(with: 17)
textField.backgroundColor = Color.clear
textField.clearButtonMode = .whileEditing
tintColor = placeholderColor
textColor = Color.darkText.primary
placeholder = "Search"
contentView.addSubview(textField)
textField.addTarget(self, action: #selector(handleEditingChanged(textField:)), for: .editingChanged)
}
/// Prepares the clearButton.
private func prepareClearButton() {
}
/// Prepares the clearButton.
fileprivate func prepareClearButton() {
clearButton = IconButton(image: Icon.cm.close, tintColor: placeholderColor)
clearButton.contentEdgeInsets = .zero
isClearButtonAutoHandleEnabled = true
textField.clearButtonMode = .never
textField.rightViewMode = .whileEditing
textField.rightView = clearButton
}
clearButton.contentEdgeInsets = .zero
isClearButtonAutoHandleEnabled = true
textField.clearButtonMode = .never
textField.rightViewMode = .whileEditing
textField.rightView = clearButton
}
}
......@@ -59,14 +59,6 @@ open class Snackbar: Bar {
open internal(set) var status = SnackbarStatus.hidden
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 {
let p = v.convert(point, from: self)
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