create separate file for cell

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-12-15 12:04:51 -06:00
parent 04bbb8948a
commit 464dd5b5e9
2 changed files with 45 additions and 1 deletions

View File

@ -64,6 +64,7 @@
EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF4292D371F00998C17 /* ButtonBase.swift */; };
EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */; };
EAB5FF0129424ACB00998C17 /* UIControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FF0029424ACB00998C17 /* UIControl.swift */; };
EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC846F2294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift */; };
EAC9257D29119B5400091998 /* TextLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257C29119B5400091998 /* TextLink.swift */; };
EAC925832911B35400091998 /* TextLinkCaret.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC925822911B35300091998 /* TextLinkCaret.swift */; };
EAC925842911C63100091998 /* Colorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEDF28F49DB3003B3210 /* Colorable.swift */; };
@ -159,6 +160,7 @@
EAB5FEF4292D371F00998C17 /* ButtonBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonBase.swift; sourceTree = "<group>"; };
EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupConstants.swift; sourceTree = "<group>"; };
EAB5FF0029424ACB00998C17 /* UIControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIControl.swift; sourceTree = "<group>"; };
EAC846F2294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupCollectionViewCell.swift; sourceTree = "<group>"; };
EAC9257C29119B5400091998 /* TextLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLink.swift; sourceTree = "<group>"; };
EAC925822911B35300091998 /* TextLinkCaret.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkCaret.swift; sourceTree = "<group>"; };
EAC925872911C9DE00091998 /* TextEntryField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextEntryField.swift; sourceTree = "<group>"; };
@ -229,8 +231,9 @@
isa = PBXGroup;
children = (
EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */,
EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */,
EAC846F2294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift */,
EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */,
EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */,
);
path = ButtonGroup;
sourceTree = "<group>";
@ -668,6 +671,7 @@
EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */,
EAF7F11728A1475A00B287F5 /* RadioButton.swift in Sources */,
EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */,
EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */,
EAF7F0952899861000B287F5 /* Checkbox.swift in Sources */,
EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */,
EAB5FEED2927E1B200998C17 /* ButtonGroupPositionLayout.swift in Sources */,

View File

@ -0,0 +1,40 @@
//
// ButtonGroupCollectionViewCell.swift
// VDS
//
// Created by Matt Bruce on 12/15/22.
//
import Foundation
import UIKit
/// Cell is needed since the buttonable hitArea "can" be outside of it's container rectangle
public class ButtonGroupCollectionViewCell: UICollectionViewCell {
var buttonable: Buttonable?
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
guard let buttonable else { return nil }
// Create a minimumHitArea variable with a value that represents the minimum size of the hit area you want to create for the button.
let minimumHitArea = CGSize(width: buttonable.intrinsicContentSize.width, height: 44)
// Create a new hitFrame variable that is the same size as the minimumHitArea variable, but is centered on the button's frame.
let hitFrame = CGRect(
x: self.bounds.midX - minimumHitArea.width / 2,
y: self.bounds.midY - minimumHitArea.height / 2,
width: minimumHitArea.width,
height: minimumHitArea.height
)
// If the point that was passed to the hitTest(_:with:) method is within the hitFrame, return the button itself. This will cause the button to handle the touch event.
if hitFrame.contains(point) {
return buttonable
}
// If the point is not within the hitFrame, return nil. This will cause the touch event to be handled by another view.
return nil
}
}