vds_ios/VDS/Protocols/AppleGuidelinesTouchable.swift
Matt Bruce 6ec498a8d7 updated comments for the AppleGuidlinesTouchable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-08-29 11:59:51 -05:00

32 lines
952 B
Swift

//
// AppleGuidelinesTouchable.swift
// VDS
//
// Created by Matt Bruce on 4/27/23.
//
import Foundation
public protocol AppleGuidelinesTouchable {
static var minimumTappableArea: CGFloat { get }
static func acceptablyOutsideBounds(point: CGPoint, bounds: CGRect) -> Bool
}
extension AppleGuidelinesTouchable {
static public var minimumTappableArea: CGFloat {
return 45.0
}
// If the control is smaller than 45pt by width or height, this will compensate.
static public func acceptablyOutsideBounds(point: CGPoint, bounds: CGRect) -> Bool {
let faultToleranceX: CGFloat = max((minimumTappableArea - bounds.size.width) / 2.0, 0)
let faultToleranceY: CGFloat = max((minimumTappableArea - bounds.size.height) / 2.0, 0)
let area = bounds.insetBy(dx: -faultToleranceX, dy: -faultToleranceY)
let contains = area.contains(point)
return contains
}
}