Merge branch 'update/icon-tooltip' into 'develop'
updated tooltip to use subset enums of Icon See merge request BPHV_MIPS/vds_ios!60
This commit is contained in:
commit
ad3de324c6
@ -238,3 +238,12 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: AppleGuidlinesTouchable
|
||||
extension ButtonBase: AppleGuidlinesTouchable {
|
||||
|
||||
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
Self.acceptablyOutsideBounds(point: point, bounds: bounds)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ open class Icon: View {
|
||||
open var color: Color = .black { didSet { didChange() }}
|
||||
open var size: Size = .medium { didSet { didChange() }}
|
||||
open var name: Name? { didSet { didChange() }}
|
||||
open var customSize: Int? { didSet { didChange() }}
|
||||
|
||||
//functions
|
||||
//--------------------------------------------------
|
||||
@ -76,7 +77,12 @@ open class Icon: View {
|
||||
}
|
||||
|
||||
//set the icon dimensions
|
||||
let dimensions = size.dimensions
|
||||
var dimensions = size.dimensions
|
||||
|
||||
if let customSize {
|
||||
dimensions = .init(width: customSize, height: customSize)
|
||||
}
|
||||
|
||||
heightConstraint?.constant = dimensions.height
|
||||
widthConstraint?.constant = dimensions.width
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
|
||||
attributedString.insert(NSAttributedString(string: spaceForTooltip), at: location)
|
||||
|
||||
//create the frame in which to hold the icon
|
||||
let frame = CGRect(x: 0, y: 0, width: size.dimensions.width, height: size.dimensions.width)
|
||||
let frame = CGRect(x: 0, y: 0, width: size.value.dimensions.width, height: size.value.dimensions.width)
|
||||
|
||||
//create the image icon and match the color of the text
|
||||
let tooltipAttribute = ImageLabelAttribute(location: location + middle,
|
||||
|
||||
@ -21,21 +21,11 @@ open class Tooltip: Control, TooltipLaunchable {
|
||||
case primary, secondary, brandHighlight
|
||||
}
|
||||
|
||||
public enum Size: String, CaseIterable {
|
||||
public enum Size: String, EnumSubset {
|
||||
case small
|
||||
case medium
|
||||
|
||||
public var dimensions: CGSize {
|
||||
switch self {
|
||||
|
||||
case .small:
|
||||
return .init(width: 13.33, height: 13.33)
|
||||
|
||||
case .medium:
|
||||
return .init(width: 16.67, height: 16.67)
|
||||
|
||||
}
|
||||
}
|
||||
public var defaultValue: Icon.Size { .small }
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -126,9 +116,9 @@ open class Tooltip: Control, TooltipLaunchable {
|
||||
addSubview(imageView)
|
||||
|
||||
imageView.pinToSuperView()
|
||||
heightConstraint = imageView.heightAnchor.constraint(equalToConstant: size.dimensions.height)
|
||||
heightConstraint = imageView.heightAnchor.constraint(equalToConstant: size.value.dimensions.height)
|
||||
heightConstraint?.isActive = true
|
||||
widthConstraint = imageView.widthAnchor.constraint(equalToConstant: size.dimensions.width)
|
||||
widthConstraint = imageView.widthAnchor.constraint(equalToConstant: size.value.dimensions.width)
|
||||
widthConstraint?.isActive = true
|
||||
|
||||
backgroundColor = .clear
|
||||
@ -160,7 +150,7 @@ open class Tooltip: Control, TooltipLaunchable {
|
||||
super.updateView()
|
||||
|
||||
//set the dimensions
|
||||
let dimensions = size.dimensions
|
||||
let dimensions = size.value.dimensions
|
||||
heightConstraint?.constant = dimensions.height
|
||||
widthConstraint?.constant = dimensions.width
|
||||
|
||||
|
||||
@ -122,11 +122,37 @@ extension UIView {
|
||||
extension UIView {
|
||||
public func debugBorder(show shouldShow: Bool = true, color: UIColor = .red) {
|
||||
if shouldShow {
|
||||
layer.borderColor = color.cgColor
|
||||
layer.borderWidth = VDSFormControls.widthBorder
|
||||
let borderLayer = CALayer()
|
||||
borderLayer.name = "debugAreaLayer"
|
||||
borderLayer.frame = bounds
|
||||
borderLayer.bounds = bounds
|
||||
borderLayer.borderWidth = VDSFormControls.widthBorder
|
||||
borderLayer.borderColor = color.cgColor
|
||||
layer.addSublayer(borderLayer)
|
||||
|
||||
if type(of: self) is AppleGuidlinesTouchable.Type {
|
||||
let faultToleranceX: CGFloat = max((45 - bounds.size.width) / 2.0, 0)
|
||||
let faultToleranceY: CGFloat = max((45 - bounds.size.height) / 2.0, 0)
|
||||
|
||||
let touchableAreaPath = UIBezierPath(rect: bounds.insetBy(dx: -faultToleranceX, dy: -faultToleranceY))
|
||||
let touchLayer = CAShapeLayer()
|
||||
touchLayer.path = touchableAreaPath.cgPath
|
||||
touchLayer.strokeColor = color.cgColor
|
||||
touchLayer.fillColor = UIColor.clear.cgColor
|
||||
touchLayer.lineWidth = VDSFormControls.widthBorder
|
||||
touchLayer.opacity = 1.0
|
||||
touchLayer.name = "debugTouchableAreaLayer"
|
||||
touchLayer.zPosition = 100
|
||||
touchLayer.frame = bounds
|
||||
touchLayer.bounds = bounds
|
||||
layer.addSublayer(touchLayer)
|
||||
}
|
||||
} else {
|
||||
layer.borderColor = UIColor.clear.cgColor
|
||||
layer.borderWidth = 0
|
||||
layer.sublayers?.forEach({ layer in
|
||||
if layer.name?.hasPrefix("debug") ?? false {
|
||||
layer.removeFromSuperlayer()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user