Skip to content

Commit 09e3f4a

Browse files
committed
Code Cleanup
1 parent 2550eb5 commit 09e3f4a

9 files changed

Lines changed: 27 additions & 210 deletions

Package.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@ let package = Package(
77
name: "FullSpeedVStack",
88
platforms: [.iOS(.v16)],
99
products: [
10-
// Products define the executables and libraries a package produces, making them visible to other packages.
1110
.library(
1211
name: "FullSpeedVStack",
1312
targets: ["FullSpeedVStack"]),
1413
],
1514
targets: [
16-
// Targets are the basic building blocks of a package, defining a module or a test suite.
17-
// Targets can depend on other targets in this package and products from dependencies.
1815
.target(
1916
name: "FullSpeedVStack"),
20-
.testTarget(
21-
name: "FullSpeedVStackTests",
22-
dependencies: ["FullSpeedVStack"]),
2317
]
2418
)

Sources/FullSpeedVStack/CollectionView/FullSpeedVStackCollectionView.swift

Lines changed: 14 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11

22
//
33
// FullSpeedVStackCollectionView.swift
4-
// Checkmate
4+
//
55
//
66
// Created by Ian Thomas on 7/26/23.
77
//
88

99
import SwiftUI
1010

11-
// #warning("need to reimplement needsToScrollToBottom for both views")
12-
1311
fileprivate struct Identifiers {
1412
fileprivate static let SupplementaryViewIdentifierHeader = "hostSupplementaryViewHeader"
1513
fileprivate static let SupplementaryViewIdentifierFooter = "hostSupplementaryViewFooter"
@@ -42,7 +40,7 @@ public struct FullSpeedVStackCollectionView<Section: SectionItemProtocol, CellIt
4240
guard let view = newValue else { return }
4341
hostController = UIHostingController(rootView: view, ignoreSafeArea: true)
4442

45-
/// This is set to .clear so that when tapping on cells the border headers, the tap selection rectangle shows.
43+
/// - Note: This is set to .clear so that when tapping on cells the border headers, the tap selection rectangle shows.
4644
hostController?.view.backgroundColor = UIColor.clear
4745
if let hostView = hostController?.view {
4846
hostView.frame = self.bounds
@@ -81,7 +79,6 @@ public struct FullSpeedVStackCollectionView<Section: SectionItemProtocol, CellIt
8179
fileprivate var dataSource: DataSource? = nil
8280
fileprivate var sectionLayoutProvider: ((Int, NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection)?
8381
fileprivate var rowsHash: Int? = nil
84-
// fileprivate var registeredSupplementaryViewKinds: [String] = []
8582
fileprivate let backgroundColor: UIColor
8683

8784
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
@@ -99,18 +96,12 @@ public struct FullSpeedVStackCollectionView<Section: SectionItemProtocol, CellIt
9996
public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
10097
self.willDisplayCell(collectionView, cell, indexPath)
10198
}
102-
103-
/// Interestingly, before the view is awoken, this is called when cells are tapped on, but after the view scrolls for the first time, this is never called again.
104-
// func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
105-
// print("here")
106-
// }
10799
}
108100

109101
let rows: [FullSpeedVStackSectionWithCells<Section, CellItem>]
110102
let sectionLayoutProvider: (Int, NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection
111103
let cell: (IndexPath, CellItem) -> CellView
112104
let supplementaryView: (String, IndexPath) -> SupplementaryView
113-
// let supplementaryViewFull: SupplementaryViewProvider
114105

115106
public typealias ScrollViewAndOptionalCollectionView = ((UIScrollView, UICollectionView?) -> Void)
116107

@@ -197,29 +188,17 @@ public struct FullSpeedVStackCollectionView<Section: SectionItemProtocol, CellIt
197188
}
198189

199190
private func handleIfNeedToScrollToItem(collectionView: UICollectionView) {
200-
201-
// guard let wrappedValue = needsToScrollToBottom?.wrappedValue,
202-
// wrappedValue else { return }
203-
204-
// print("handleIfNeedToScrollToItem")
205191
guard let scrollItem = self.needsToScrollToItem?.wrappedValue else { return }
206-
207192
guard collectionView.isValid(indexPath: scrollItem.indexPath) else {
208-
// print("Error: indexPath \(scrollItem.indexPath) not valid")
209193
return
210194
}
211195
collectionViewScrollToIndexPath(collectionView: collectionView, scrollItem: scrollItem)
212-
213-
// NotificationCenter.default.post(name: .scrollToBottomOfChatRoomSetFalse, object: nil)
214196
}
215-
//
197+
216198
private func collectionViewScrollToIndexPath(collectionView: UICollectionView, scrollItem: ScrollToItemAnimated) {
217199

218200
DispatchQueue.main.async {
219-
// print("executing scroll to: \(scrollItem.indexPath)")
220201
collectionView.scrollToItem(at: scrollItem.indexPath, at: .centeredVertically, animated: scrollItem.animated)
221-
// let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
222-
// collectionView.scrollRectToVisible(rect, animated: false)
223202
NotificationCenter.default.post(name: .FullSpeedVStackSetScrollToIndexPathNil, object: FullSpeedVStackSetScrollToIndexPathNilNotification(collectionViewIdentifier: self.collectionViewId))
224203
}
225204
}
@@ -242,10 +221,6 @@ public struct FullSpeedVStackCollectionView<Section: SectionItemProtocol, CellIt
242221

243222
context.coordinator.collectionViewReference = collectionView
244223

245-
// collectionView.keyboardDismissMode = .interactive
246-
247-
// collectionView.showsVerticalScrollIndicator = false
248-
249224
collectionView.delegate = context.coordinator
250225
collectionView.register(HostCell.self, forCellWithReuseIdentifier: cellIdentifier)
251226

@@ -263,8 +238,7 @@ public struct FullSpeedVStackCollectionView<Section: SectionItemProtocol, CellIt
263238
/// `UIHostingConfiguration` has extra layout margins that need to be removed.
264239
.margins(.all, 0)
265240

266-
// hostCell?.si
267-
/// if the cells are not sizing properly, try adding sizeToFit(), but will likely need more handholding to make production ready.
241+
/// - Note: If the cells are not sizing properly, try adding sizeToFit()
268242

269243
if invertView {
270244
hostCell?.contentView.transform = CGAffineTransform(scaleX: 1, y: -1)
@@ -273,8 +247,7 @@ public struct FullSpeedVStackCollectionView<Section: SectionItemProtocol, CellIt
273247
}
274248
context.coordinator.dataSource = dataSource
275249

276-
/// There was a memory leak that the debugger said was linked to the supplementary view, so I moved the registration outside the following closure and it appeared to work
277-
250+
/// - Note: There was a memory leak that the debugger said was linked to the supplementary view, so I moved the registration outside the following closure to resile the issue
278251
collectionView.register(HostSupplementaryView.self,
279252
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
280253
withReuseIdentifier: Identifiers.SupplementaryViewIdentifierHeader)
@@ -309,7 +282,7 @@ public struct FullSpeedVStackCollectionView<Section: SectionItemProtocol, CellIt
309282
}
310283
}
311284

312-
/// This is so we can override `gestureRecognizerShouldBegin`
285+
/// We subclass `UICollectionView` to override `gestureRecognizerShouldBegin`
313286
final fileprivate class CustomUICollectionView: UICollectionView {
314287

315288
init(frame: CGRect,
@@ -327,71 +300,31 @@ final fileprivate class CustomUICollectionView: UICollectionView {
327300
self.transform = CGAffineTransform(scaleX: 1, y: -1)
328301
}
329302

330-
// NotificationCenter.default.addObserver(self, selector: #selector(scrollToIndexPath), name: .FullSpeedVStackScrollToIndexPath, object: nil)
331-
332303
NotificationCenter.default.addObserver(self, selector: #selector(awakeScroll), name: .FullSpeedVStackAwakeScroll, object: nil)
333-
334-
// TODO: add chat list scroll to top
335-
// NotificationCenter.default.addObserver(self, selector: #selector(scrollToTop), name: .friendListScrollToTop, object: nil)
336304
}
337305

338306
private let collectionViewId: String
339307

340-
// @objc private func scrollToBottomOfChatRoom(_ notification: Notification) {
341-
//
342-
// let y = contentSize.height - 1
343-
// let rect = CGRect(x: 0, y: y + safeAreaInsets.bottom, width: 1, height: 1)
344-
// scrollRectToVisible(rect, animated: true)
345-
// }
346-
//
347-
// @objc private func scrollToIndexPath(_ notification: Notification) {
348-
//
349-
// guard let scrollObject = notification.object as? FullSpeedVStackScrollToIndexPathNotification else { return }
350-
// TODO: Handle is empty chat list
351-
// scrollObject.indexPath
352-
// guard scrollObject.collectionViewId == self.collectionViewId else { return }
353-
354-
// guard let theIndexPath.collectionViewIdentifier == self.collectionViewId else { return }
355-
356-
// self.scrollToItem(at: scrollObject.indexPath, at: .bottom, animated: false)
357-
// }
358-
359-
#warning("add keyboard to both collection and table view")
360-
// @objc private func adjustForKeyboard(notification: Notification) {
361-
362308
@objc private func keyboardWillChangeFrame(_ notification: Notification) {
363-
guard
364-
let userInfo = notification.userInfo,
365-
let endPos = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
366-
else { return }
367-
368-
let keyboardHeightDynamic = endPos.height
369-
370-
#warning("fix this, the height / inset is not correct")
309+
// guard
310+
// let userInfo = notification.userInfo,
311+
// let endPos = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
312+
// else { return }
313+
//
314+
// let keyboardHeightDynamic = endPos.height
371315
/*
372316
self.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardHeightDynamic, right: 0)
373317
self.scrollIndicatorInsets = self.contentInset
374-
*/
375-
// print("keyboardHeight", keyboardHeight)
318+
*/
376319
}
377320

378-
//
379-
// if notification.name == UIResponder.keyboardWillHideNotification {
380-
// self.contentInset = .zero
381-
// } else {
382-
// let height = OnboardingConstants.KeyboardSizeOnly(includesSuggestionBar: false)
383-
// self.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: height, right: 0)
384-
// }
385-
//
386-
//}
387-
//
388321
private var hasAwoken = false
389322

390323
required init?(coder: NSCoder) {
391324
fatalError("init(coder:) has not been implemented")
392325
}
393326

394-
/// The missing taps issue, where the tapping on a cell has no effect until the user scrolls.
327+
/// The missing taps issue: where the tapping on a cell has no effect until the user scrolls.
395328
///
396329
/// if you add `override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView?` to the `HostSupplementaryView` and other reasonable places it does not appear to work.
397330
///
@@ -401,7 +334,6 @@ final fileprivate class CustomUICollectionView: UICollectionView {
401334
/// - adding to the SwiftUI View `.allowsHitTesting(true)`
402335

403336
@objc func awakeScroll() {
404-
// print("awakeScroll")
405337

406338
guard hasAwoken == false else { return }
407339
hasAwoken = true
@@ -413,33 +345,6 @@ final fileprivate class CustomUICollectionView: UICollectionView {
413345
}
414346
}
415347

416-
// @objc func scrollToTop() {
417-
// self.setContentOffset(CGPoint.zero, animated: true)
418-
// }
419-
420-
// public func sendVisibleRows() {
421-
// self.visibleCells
422-
// }
423-
424-
425-
// public func keepCurrentScroll(for upsertedMessages: [BaseMessage]) -> IndexPath {
426-
// let firstVisibleIndexPath = tableView
427-
// .indexPathsForVisibleRows?.first ?? IndexPath(row: 0, section: 0)
428-
// var nextInsertedCount = 0
429-
// if let newestMessage = sentMessages.first {
430-
// // only filter out messages inserted at the bottom (newer) of current visible item
431-
// nextInsertedCount = upsertedMessages
432-
// .filter({ $0.createdAt > newestMessage.createdAt })
433-
// .filter({ !SBUUtils.contains(messageId: $0.messageId, in: sentMessages) }).count
434-
// }
435-
//
436-
// SBULog.info("New messages inserted : \(nextInsertedCount)")
437-
// return IndexPath(
438-
// row: firstVisibleIndexPath.row + nextInsertedCount,
439-
// section: 0
440-
// )
441-
// }
442-
443348
var onGestureShouldBegin: ((_ gestureRecognizer: UIPanGestureRecognizer, _ scrollView: UIScrollView) -> Bool)?
444349

445350
public override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {

Sources/FullSpeedVStack/CollectionView/Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# README
22

3-
/// When it's an enum with an associated value, make sure that value that is in `hash(into` is that associated value.
3+
/// When it's an enum with an associated value, make sure that value that is in `hash(into)` is that associated value.
44
/*
55
func hash(into hasher: inout Hasher) {
66
switch self {
77
case .topLine(let viewModel):
88
hasher.combine(viewModel)
99
*/
10-
/// Also do a big switch statement for the `static func ==`
10+
/// Also completely fill-out the switch statement for the `static func ==`
1111
/*
1212
static func == (lhs: ProfileCellViewModel, rhs: ProfileCellViewModel) -> Bool {
1313
switch (lhs, rhs) {

Sources/FullSpeedVStack/FullSpeedVStack+Testing.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ fileprivate class TestViewModel: ObservableObject {
3636
CellViewModel(),
3737
CellViewModel(),
3838
]
39-
//= Array.init(repeating: CellViewModel(), count: 20)
4039
sectionsDisplayed = [
4140
SectionWithCellsItem(section: SectionType.main, items: cells, displaySectionsWhenEmpty: true)
4241
]
@@ -45,13 +44,7 @@ fileprivate class TestViewModel: ObservableObject {
4544
}
4645

4746
@objc private func setScrollToItemFalse(_ notification: Notification) {
48-
print("setScrollToItemFalse")
49-
// guard let object = notification.object as? FullSpeedVStackSetScrollToIndexPathNilNotification, object.collectionViewId == self.collectionViewId else {
50-
// print("wrong id")
51-
// return
52-
// }
5347
DispatchQueue.main.async { [weak self] in
54-
// print("scrollToItem = nil")
5548
self?.scrollToItem = nil
5649
}
5750
}

Sources/FullSpeedVStack/FullSpeedVStackSectionWithCells.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// FullSpeedVStackSectionWithCells.swift
3-
// Checkmate
3+
//
44
//
55
// Created by Ian Thomas on 8/14/23.
66
//
@@ -14,14 +14,14 @@ public protocol SectionItemProtocol: Hashable, Comparable, CaseIterable {
1414
var headerString: String { get }
1515
}
1616

17-
/// When it's an enum with an associated value, make sure that value that is in `hash(into` is that associated value.
17+
/// When it's an enum with an associated value, make sure that value that is in `hash(into)` is that associated value.
1818
/*
1919
func hash(into hasher: inout Hasher) {
2020
switch self {
2121
case .topLineNumbers(let viewModel):
2222
hasher.combine(viewModel)
2323
*/
24-
/// Also do a big switch statement for the `static func ==`
24+
/// Also completely fill-out the switch statement for the `static func ==`
2525
/*
2626
static func == (lhs: UserProfileCellViewModel, rhs: UserProfileCellViewModel) -> Bool {
2727
switch (lhs, rhs) {
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,23 @@
11
//
2-
// File.swift
2+
// Notification+Extension.swift
33
//
44
//
55
// Created by Ian Thomas on 5/9/24.
66
//
77

88
import Foundation
9-
/*
10-
public struct FullSpeedVStackScrollToIndexPathNotification {
11-
12-
/// Since this notification is on all the collection views, we want to send the scroll to action to a specific one.
13-
public init(collectionViewIdentifier: String, indexPath: IndexPath) {
14-
self.collectionViewId = collectionViewIdentifier
15-
self.indexPath = indexPath
16-
}
17-
18-
let collectionViewId: String
19-
let indexPath: IndexPath
20-
}
21-
*/
9+
2210
public struct FullSpeedVStackSetScrollToIndexPathNilNotification {
2311

24-
/// Since this notification is on all the collection views, we want to send the scroll to action to a specific one.
12+
/// Since this notification observer is on all the collection views, we want to send the scroll to action to a specific one.
2513
public init(collectionViewIdentifier: String) {
2614
self.collectionViewId = collectionViewIdentifier
2715
}
2816

2917
public let collectionViewId: String
3018
}
3119

32-
3320
extension Notification.Name {
3421
public static let FullSpeedVStackSetScrollToIndexPathNil = Notification.Name("FullSpeedVStackSetScrollToIndexPathNil")
3522
public static let FullSpeedVStackAwakeScroll = Notification.Name("FullSpeedVStackAwakeScroll")
36-
37-
// public static let FullSpeedVStackScrollToIndexPath = Notification.Name("FullSpeedVStackScrollToIndexPath")
3823
}

0 commit comments

Comments
 (0)