moved out methods to constants
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
2050896483
commit
1257112c06
@ -62,6 +62,7 @@
|
|||||||
EAB5FEED2927E1B200998C17 /* ButtonGroupPositionLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */; };
|
EAB5FEED2927E1B200998C17 /* ButtonGroupPositionLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */; };
|
||||||
EAB5FEF12927F4AA00998C17 /* SelfSizingCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */; };
|
EAB5FEF12927F4AA00998C17 /* SelfSizingCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */; };
|
||||||
EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF4292D371F00998C17 /* ButtonBase.swift */; };
|
EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF4292D371F00998C17 /* ButtonBase.swift */; };
|
||||||
|
EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */; };
|
||||||
EAC9257D29119B5400091998 /* TextLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257C29119B5400091998 /* TextLink.swift */; };
|
EAC9257D29119B5400091998 /* TextLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257C29119B5400091998 /* TextLink.swift */; };
|
||||||
EAC925832911B35400091998 /* TextLinkCaret.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC925822911B35300091998 /* TextLinkCaret.swift */; };
|
EAC925832911B35400091998 /* TextLinkCaret.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC925822911B35300091998 /* TextLinkCaret.swift */; };
|
||||||
EAC925842911C63100091998 /* Colorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEDF28F49DB3003B3210 /* Colorable.swift */; };
|
EAC925842911C63100091998 /* Colorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEDF28F49DB3003B3210 /* Colorable.swift */; };
|
||||||
@ -155,6 +156,7 @@
|
|||||||
EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupPositionLayout.swift; sourceTree = "<group>"; };
|
EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupPositionLayout.swift; sourceTree = "<group>"; };
|
||||||
EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingCollectionView.swift; sourceTree = "<group>"; };
|
EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingCollectionView.swift; sourceTree = "<group>"; };
|
||||||
EAB5FEF4292D371F00998C17 /* ButtonBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonBase.swift; sourceTree = "<group>"; };
|
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>"; };
|
||||||
EAC9257C29119B5400091998 /* TextLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLink.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>"; };
|
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>"; };
|
EAC925872911C9DE00091998 /* TextEntryField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextEntryField.swift; sourceTree = "<group>"; };
|
||||||
@ -226,6 +228,7 @@
|
|||||||
children = (
|
children = (
|
||||||
EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */,
|
EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */,
|
||||||
EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */,
|
EAB5FEEC2927E1B200998C17 /* ButtonGroupPositionLayout.swift */,
|
||||||
|
EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */,
|
||||||
);
|
);
|
||||||
path = ButtonGroup;
|
path = ButtonGroup;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -680,6 +683,7 @@
|
|||||||
EAB1D2CF28ABEF2B00DAE764 /* Typography.swift in Sources */,
|
EAB1D2CF28ABEF2B00DAE764 /* Typography.swift in Sources */,
|
||||||
EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */,
|
EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */,
|
||||||
EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */,
|
EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */,
|
||||||
|
EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */,
|
||||||
EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */,
|
EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */,
|
||||||
EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */,
|
EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */,
|
||||||
EAF7F09E289AAEC000B287F5 /* Constants.swift in Sources */,
|
EAF7F09E289AAEC000B287F5 /* Constants.swift in Sources */,
|
||||||
|
|||||||
130
VDS/Components/Buttons/ButtonGroup/ButtonGroupConstants.swift
Normal file
130
VDS/Components/Buttons/ButtonGroup/ButtonGroupConstants.swift
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
//
|
||||||
|
// ButtonGroupConstants.swift
|
||||||
|
// VDS
|
||||||
|
//
|
||||||
|
// Created by Matt Bruce on 12/1/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct ButtonGroupConstants {
|
||||||
|
static let rowSpacingButton = 12.0
|
||||||
|
static let rowSpacingTextLink = 12.0
|
||||||
|
|
||||||
|
static func getHorizontalSpacing(for primary: Buttonable, neighboring: Buttonable) -> CGFloat {
|
||||||
|
let defaultSpace = 12.0
|
||||||
|
//large button
|
||||||
|
if let button = primary as? Button, button.size == .large {
|
||||||
|
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
|
||||||
|
return 12.0
|
||||||
|
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
|
||||||
|
return 16.0
|
||||||
|
} else if let _ = neighboring as? TextLinkCaret {
|
||||||
|
return 24.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//large text link
|
||||||
|
else if let textLink = primary as? TextLink, textLink.size == .large {
|
||||||
|
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
|
||||||
|
return 16.0
|
||||||
|
} else if let _ = neighboring as? TextLinkCaret {
|
||||||
|
return 24.0
|
||||||
|
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
|
||||||
|
return 16.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//text link caret
|
||||||
|
else if let _ = primary as? TextLinkCaret {
|
||||||
|
if let _ = neighboring as? TextLinkCaret {
|
||||||
|
return 24.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//small button
|
||||||
|
else if let button = primary as? Button, button.size == .small {
|
||||||
|
if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
|
||||||
|
return 12.0
|
||||||
|
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
|
||||||
|
return 16.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//small text link
|
||||||
|
else if let textLink = primary as? TextLink, textLink.size == .small {
|
||||||
|
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
|
||||||
|
return 16.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//return defaultSpace
|
||||||
|
else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static func getVerticalSpacing(for primary: Buttonable, neighboring: Buttonable) -> CGFloat {
|
||||||
|
let defaultSpace = 12.0
|
||||||
|
//large button
|
||||||
|
if let button = primary as? Button, button.size == .large {
|
||||||
|
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
|
||||||
|
return 12.0
|
||||||
|
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
|
||||||
|
return 16.0
|
||||||
|
} else if let _ = neighboring as? TextLinkCaret {
|
||||||
|
return 24.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//large text link
|
||||||
|
else if let textLink = primary as? TextLink, textLink.size == .large {
|
||||||
|
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
|
||||||
|
return 16.0
|
||||||
|
} else if let _ = neighboring as? TextLinkCaret {
|
||||||
|
return 24.0
|
||||||
|
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
|
||||||
|
return 24.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//text link caret
|
||||||
|
else if let _ = primary as? TextLinkCaret {
|
||||||
|
if let _ = neighboring as? TextLinkCaret {
|
||||||
|
return 24.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//small button
|
||||||
|
else if let button = primary as? Button, button.size == .small {
|
||||||
|
if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
|
||||||
|
return 12.0
|
||||||
|
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
|
||||||
|
return 24.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//small text link
|
||||||
|
else if let textLink = primary as? TextLink, textLink.size == .small {
|
||||||
|
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
|
||||||
|
return 32.0
|
||||||
|
} else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//return defaultSpace
|
||||||
|
else {
|
||||||
|
return defaultSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -8,23 +8,11 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class ButtonLayoutAttributes: UICollectionViewLayoutAttributes{
|
|
||||||
var spacing: CGFloat = 0
|
|
||||||
var isButton: Bool = false
|
|
||||||
convenience init(spacing: CGFloat,
|
|
||||||
forCellWith indexPath: IndexPath) {
|
|
||||||
self.init(forCellWith: indexPath)
|
|
||||||
self.spacing = spacing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ButtonCollectionViewRow {
|
class ButtonCollectionViewRow {
|
||||||
var attributes = [ButtonLayoutAttributes]()
|
var attributes = [ButtonLayoutAttributes]()
|
||||||
var spacing: CGFloat = 0
|
|
||||||
|
|
||||||
init(spacing: CGFloat) {
|
init() {}
|
||||||
self.spacing = spacing
|
|
||||||
}
|
|
||||||
|
|
||||||
func add(attribute: ButtonLayoutAttributes) {
|
func add(attribute: ButtonLayoutAttributes) {
|
||||||
attributes.append(attribute)
|
attributes.append(attribute)
|
||||||
@ -83,6 +71,16 @@ protocol ButtongGroupPositionLayoutDelegate: AnyObject {
|
|||||||
func collectionView(_ collectionView: UICollectionView, insetsForItemsInSection section: Int) -> UIEdgeInsets
|
func collectionView(_ collectionView: UICollectionView, insetsForItemsInSection section: Int) -> UIEdgeInsets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ButtonLayoutAttributes: UICollectionViewLayoutAttributes{
|
||||||
|
var spacing: CGFloat = 0
|
||||||
|
var isButton: Bool = false
|
||||||
|
convenience init(spacing: CGFloat,
|
||||||
|
forCellWith indexPath: IndexPath) {
|
||||||
|
self.init(forCellWith: indexPath)
|
||||||
|
self.spacing = spacing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ButtonGroupPositionLayout: UICollectionViewLayout {
|
class ButtonGroupPositionLayout: UICollectionViewLayout {
|
||||||
|
|
||||||
weak var delegate: ButtongGroupPositionLayoutDelegate?
|
weak var delegate: ButtongGroupPositionLayoutDelegate?
|
||||||
@ -94,33 +92,36 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
|
|||||||
|
|
||||||
override func prepare() {
|
override func prepare() {
|
||||||
super.prepare()
|
super.prepare()
|
||||||
|
|
||||||
let rowSpacingButton = 12.0
|
|
||||||
let rowSpacingTextLink = 12.0
|
|
||||||
|
|
||||||
itemCache.removeAll()
|
itemCache.removeAll()
|
||||||
layoutHeight = 0.0
|
layoutHeight = 0.0
|
||||||
|
|
||||||
guard let collectionView, let delegate else {
|
guard let collectionView, let delegate else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var itemSpacing = 0.0
|
|
||||||
|
|
||||||
// Variable to track the width of the layout at the current state when the item is being drawn
|
// Variable to track the width of the layout at the current state when the item is being drawn
|
||||||
var layoutWidthIterator: CGFloat = 0.0
|
var layoutWidthIterator: CGFloat = 0.0
|
||||||
|
|
||||||
|
// Only 1 section in the ButtonGroup
|
||||||
let section = 0
|
let section = 0
|
||||||
|
|
||||||
// Get the necessary data (if implemented) from the delegates else provide default values
|
// Get the necessary data (if implemented) from the delegates else provide default values
|
||||||
let insets: UIEdgeInsets = delegate.collectionView(collectionView, insetsForItemsInSection: section)
|
let insets: UIEdgeInsets = delegate.collectionView(collectionView, insetsForItemsInSection: section)
|
||||||
let rowSpacing: CGFloat = rowSpacingButton
|
|
||||||
|
let rowSpacing: CGFloat = ButtonGroupConstants.rowSpacingButton
|
||||||
|
|
||||||
// Variables to track individual item width and cumultative height of all items as they are being laid out.
|
// Variables to track individual item width and cumultative height of all items as they are being laid out.
|
||||||
var itemSize: CGSize = .zero
|
var itemSize: CGSize = .zero
|
||||||
|
|
||||||
|
// add top
|
||||||
layoutHeight += insets.top
|
layoutHeight += insets.top
|
||||||
|
|
||||||
let totalItems = collectionView.numberOfItems(inSection: section)
|
let totalItems = collectionView.numberOfItems(inSection: section)
|
||||||
for item in 0..<totalItems {
|
for item in 0..<totalItems {
|
||||||
|
|
||||||
itemSpacing = 0.0
|
var itemSpacing = 0.0
|
||||||
|
|
||||||
let indexPath = IndexPath(item: item, section: section)
|
let indexPath = IndexPath(item: item, section: section)
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
|
|||||||
let nextItem = item + 1
|
let nextItem = item + 1
|
||||||
if nextItem < totalItems {
|
if nextItem < totalItems {
|
||||||
let neighbor = delegate.collectionView(collectionView, buttonableAtIndexPath: IndexPath(item: nextItem, section: section))
|
let neighbor = delegate.collectionView(collectionView, buttonableAtIndexPath: IndexPath(item: nextItem, section: section))
|
||||||
itemSpacing = getHorizontalSpacing(for: itemButtonable, neighboring: neighbor)
|
itemSpacing = ButtonGroupConstants.getHorizontalSpacing(for: itemButtonable, neighboring: neighbor)
|
||||||
}
|
}
|
||||||
|
|
||||||
let frame = CGRect(x: layoutWidthIterator + insets.left, y: layoutHeight, width: itemSize.width, height: itemSize.height)
|
let frame = CGRect(x: layoutWidthIterator + insets.left, y: layoutHeight, width: itemSize.width, height: itemSize.height)
|
||||||
@ -149,7 +150,8 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
|
|||||||
|
|
||||||
layoutWidthIterator = layoutWidthIterator + frame.width + itemSpacing
|
layoutWidthIterator = layoutWidthIterator + frame.width + itemSpacing
|
||||||
}
|
}
|
||||||
//print("*******")
|
|
||||||
|
//add bottom
|
||||||
layoutHeight += itemSize.height + insets.bottom
|
layoutHeight += itemSize.height + insets.bottom
|
||||||
layoutWidthIterator = 0.0
|
layoutWidthIterator = 0.0
|
||||||
|
|
||||||
@ -161,7 +163,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
|
|||||||
for attribute in itemCache {
|
for attribute in itemCache {
|
||||||
if currentRowY != attribute.frame.midY {
|
if currentRowY != attribute.frame.midY {
|
||||||
currentRowY = attribute.frame.midY
|
currentRowY = attribute.frame.midY
|
||||||
rows.append(ButtonCollectionViewRow(spacing: itemSpacing))
|
rows.append(ButtonCollectionViewRow())
|
||||||
}
|
}
|
||||||
rows.last?.add(attribute: attribute)
|
rows.last?.add(attribute: attribute)
|
||||||
}
|
}
|
||||||
@ -176,7 +178,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
|
|||||||
var rowSpacing = 0.0
|
var rowSpacing = 0.0
|
||||||
|
|
||||||
if item > 0 && item < rows.count {
|
if item > 0 && item < rows.count {
|
||||||
rowSpacing = row.hasButtons ? rowSpacingButton : rowSpacingTextLink
|
rowSpacing = row.hasButtons ? ButtonGroupConstants.rowSpacingButton : ButtonGroupConstants.rowSpacingTextLink
|
||||||
}
|
}
|
||||||
|
|
||||||
if item > 0 {
|
if item > 0 {
|
||||||
@ -200,123 +202,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHorizontalSpacing(for primary: Buttonable, neighboring: Buttonable) -> CGFloat {
|
|
||||||
let defaultSpace = 12.0
|
|
||||||
//large button
|
|
||||||
if let button = primary as? Button, button.size == .large {
|
|
||||||
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
|
|
||||||
return 12.0
|
|
||||||
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
|
|
||||||
return 16.0
|
|
||||||
} else if let _ = neighboring as? TextLinkCaret {
|
|
||||||
return 24.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//large text link
|
|
||||||
else if let textLink = primary as? TextLink, textLink.size == .large {
|
|
||||||
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
|
|
||||||
return 16.0
|
|
||||||
} else if let _ = neighboring as? TextLinkCaret {
|
|
||||||
return 24.0
|
|
||||||
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
|
|
||||||
return 16.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//text link caret
|
|
||||||
else if let _ = primary as? TextLinkCaret {
|
|
||||||
if let _ = neighboring as? TextLinkCaret {
|
|
||||||
return 24.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//small button
|
|
||||||
else if let button = primary as? Button, button.size == .small {
|
|
||||||
if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
|
|
||||||
return 12.0
|
|
||||||
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
|
|
||||||
return 16.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//small text link
|
|
||||||
else if let textLink = primary as? TextLink, textLink.size == .small {
|
|
||||||
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
|
|
||||||
return 16.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//return defaultSpace
|
|
||||||
else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getVerticalSpacing(for primary: Buttonable, neighboring: Buttonable) -> CGFloat {
|
|
||||||
let defaultSpace = 12.0
|
|
||||||
//large button
|
|
||||||
if let button = primary as? Button, button.size == .large {
|
|
||||||
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
|
|
||||||
return 12.0
|
|
||||||
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
|
|
||||||
return 16.0
|
|
||||||
} else if let _ = neighboring as? TextLinkCaret {
|
|
||||||
return 24.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//large text link
|
|
||||||
else if let textLink = primary as? TextLink, textLink.size == .large {
|
|
||||||
if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
|
|
||||||
return 16.0
|
|
||||||
} else if let _ = neighboring as? TextLinkCaret {
|
|
||||||
return 24.0
|
|
||||||
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
|
|
||||||
return 24.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//text link caret
|
|
||||||
else if let _ = primary as? TextLinkCaret {
|
|
||||||
if let _ = neighboring as? TextLinkCaret {
|
|
||||||
return 24.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//small button
|
|
||||||
else if let button = primary as? Button, button.size == .small {
|
|
||||||
if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
|
|
||||||
return 12.0
|
|
||||||
} else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
|
|
||||||
return 24.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//small text link
|
|
||||||
else if let textLink = primary as? TextLink, textLink.size == .small {
|
|
||||||
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
|
|
||||||
return 32.0
|
|
||||||
} else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//return defaultSpace
|
|
||||||
else {
|
|
||||||
return defaultSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override func layoutAttributesForElements(in rect: CGRect)-> [UICollectionViewLayoutAttributes]? {
|
override func layoutAttributesForElements(in rect: CGRect)-> [UICollectionViewLayoutAttributes]? {
|
||||||
var visibleLayoutAttributes: [UICollectionViewLayoutAttributes] = []
|
var visibleLayoutAttributes: [UICollectionViewLayoutAttributes] = []
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user