Skip to content

Commit

Permalink
Moved to SPM
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcruzeiro committed Nov 5, 2021
1 parent d148157 commit c6d0382
Show file tree
Hide file tree
Showing 47 changed files with 2,128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ DerivedData
*.hmap
*.ipa

.swiftpm

# Bundler
.bundle

Expand Down
52 changes: 52 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"object": {
"pins": [
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "35f9e770f54ce62dd8526470f14c6e137cef3eea",
"version": "2.1.1"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "fb7a26374e8570ff5c68142e5c83406d6abae0d8",
"version": "2.0.2"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble",
"state": {
"branch": null,
"revision": "c93f16c25af5770f0d3e6af27c9634640946b068",
"version": "9.2.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick",
"state": {
"branch": null,
"revision": "bd86ca0141e3cfb333546de5a11ede63f0c4a0e6",
"version": "4.0.0"
}
},
{
"package": "RxSwift",
"repositoryURL": "https://github.com/ReactiveX/RxSwift/",
"state": {
"branch": null,
"revision": "7c17a6ccca06b5c107cfa4284e634562ddaf5951",
"version": "6.2.0"
}
}
]
},
"version": 1
}
34 changes: 34 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Coordinators",
platforms: [.iOS(.v13)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Coordinators",
targets: ["Coordinators"]),
],
dependencies: [
.package(url: "https://github.com/Quick/Quick", from: "4.0.0"),
.package(url: "https://github.com/Quick/Nimble", from: "9.2.1"),
.package(url: "https://github.com/ReactiveX/RxSwift/", from: "6.2.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Coordinators",
dependencies: ["RxSwift"]),
.testTarget(
name: "CoordinatorsTests",
dependencies: [
"Coordinators",
"Quick",
"Nimble"
]),
]
)
54 changes: 54 additions & 0 deletions Sources/Coordinators/CCollectionViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// CCollectionViewController.swift
// Coordinators
//
// Created by Raphael Cruzeiro on 11/08/2021.
//

import UIKit

open class CCollectionViewController<V: UIView & CollectionViewHolder, VM: ListViewModel, C: CCollectionViewCell<VM.Item>>: CViewModelViewController<V, VM>, CollectionViewHolder, UICollectionViewDataSource {

open override func setup() {
super.setup()

collectionView.register(C.self)
collectionView.dataSource = self
}

open var collectionView: UICollectionView {
return hostedView.collectionView
}

open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
setupBottomPaneInsets()
}

open func numberOfSections(in collectionView: UICollectionView) -> Int {
return viewModel.sections.count
}

open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
guard let section = viewModel.section(for: section) else { return 0 }
return section.items.count
}

open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: C = collectionView.dequeue(for: indexPath)
cell.item = viewModel.item(for: indexPath)

return cell
}

open func collectionView(_ collectionView: UITableView, titleForHeaderInSection section: Int) -> String? {
return viewModel.section(for: section)?.title
}

public func setupBottomPaneInsets() {
super.setupBottomPaneInsets()
adjustScrolViewInsets(scrollView, for: bottomPaneView)
}

}

20 changes: 20 additions & 0 deletions Sources/Coordinators/CHostingViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// CHostingViewController.swift
// Coordinators
//
// Created by Raphael Cruzeiro on 18/07/2021.
//

import UIKit

open class CHostingViewController<V: UIView>: CViewController {

open var hostedView: V {
return view as! V
}

open override func loadView() {
self.view = V()
}

}
31 changes: 31 additions & 0 deletions Sources/Coordinators/CNavigationController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// CNavigationController.swift
// Coordinators
//
// Created by Raphael Cruzeiro on 30/09/2019.
//

import UIKit

open class CNavigationController: UINavigationController, CViewControllerProtocol {

weak public var cViewControllerDelegate: CViewControllerDelegate?

override open func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
setPresentationControllerDelegate(viewControllerToPresent: viewControllerToPresent)
super.present(viewControllerToPresent, animated: flag, completion: completion)
}

}

extension CNavigationController: UIAdaptivePresentationControllerDelegate {

open func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {
(presentationController.presentedViewController as? CViewControllerProtocol)?.cViewControllerDelegate?.cViewControllerWillDismiss(presentationController.presentedViewController)
}

open func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
(presentationController.presentedViewController as? CViewControllerProtocol)?.cViewControllerDelegate?.cViewControllerDidDismiss(presentationController.presentedViewController)
}

}
71 changes: 71 additions & 0 deletions Sources/Coordinators/CScrollViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// CScrollViewController.swift
// Coordinators
//
// Created by Raphael Cruzeiro on 19/07/2021.
//

import UIKit

open class CScrollViewController<V: UIView & ScrollViewHolder>: CHostingViewController<V> {

let keyboardAnimationTime: TimeInterval = 0.3

private var keyboardBottomConstraint: NSLayoutConstraint?

public var scrollView: UIScrollView {
return hostedView.scrollView
}

open var scrollViewKeyboardAdjustment: ScrollViewKeyboardAdjustment {
return .none
}

open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
setupBottomPaneInsets()
}

open override func keyboardWillShow(endframe: CGRect?) {
super.keyboardWillShow(endframe: endframe)

switch scrollViewKeyboardAdjustment {
case .bottomConstraint:
let contraint = scrollView.bottomAnchor.constraint(equalTo: hostedView.bottomAnchor, constant: (endframe?.height ?? 0) * -1)
contraint.priority = .required
contraint.isActive = true
keyboardBottomConstraint = contraint
hostedView.setNeedsLayout()

UIView.animate(withDuration: keyboardAnimationTime, animations: hostedView.layoutIfNeeded)
case .contentInset:
UIView.animate(withDuration: keyboardAnimationTime) {
self.scrollView.contentInset.bottom = (endframe?.height ?? 0)
}
default:
break
}
}

open override func keyboardWillHide(endframe: CGRect?) {
super.keyboardWillHide(endframe: endframe)

switch scrollViewKeyboardAdjustment {
case .contentInset:
UIView.animate(withDuration: keyboardAnimationTime) {
self.scrollView.contentInset.bottom = 0
}
case .bottomConstraint:
keyboardBottomConstraint?.isActive = false
keyboardBottomConstraint = nil
default:
break
}
}

public func setupBottomPaneInsets() {
super.setupBottomPaneInsets()
adjustScrolViewInsets(scrollView, for: bottomPaneView)
}

}
53 changes: 53 additions & 0 deletions Sources/Coordinators/CTableViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// CTableViewController.swift
// Coordinators
//
// Created by Raphael Cruzeiro on 18/07/2021.
//

import UIKit

open class CTableViewController<V: UIView & TableViewHolder, VM: ListViewModel, C: CTableViewCell<VM.Item>>: CViewModelViewController<V, VM>, TableViewHolder, UITableViewDataSource {

open override func setup() {
super.setup()

tableView.register(C.self)
tableView.dataSource = self
}

open var tableView: UITableView {
return hostedView.tableView
}

open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
setupBottomPaneInsets()
}

open func numberOfSections(in tableView: UITableView) -> Int {
return viewModel.numberOfSections
}

open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let section = viewModel.section(for: section) else { return 0 }
return section.items.count
}

open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: C = tableView.dequeue(for: indexPath)
cell.item = viewModel.item(for: indexPath)

return cell
}

open func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return viewModel.section(for: section)?.title
}

public func setupBottomPaneInsets() {
super.setupBottomPaneInsets()
adjustScrolViewInsets(scrollView, for: bottomPaneView)
}

}
Loading

0 comments on commit c6d0382

Please sign in to comment.