Skip to content

Commit

Permalink
Remove SnapKit Dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
bstillitano committed Apr 20, 2022
1 parent 2a949a1 commit 606ca17
Show file tree
Hide file tree
Showing 28 changed files with 1,234 additions and 311 deletions.
16 changes: 0 additions & 16 deletions Package.resolved

This file was deleted.

4 changes: 0 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import PackageDescription
let package = Package(
name: "Scyther",
platforms: [
.macOS(.v10_14),
.iOS(.v13)
],
products: [
Expand All @@ -18,8 +17,6 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/SnapKit/SnapKit",
from: "5.0.1")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -32,7 +29,6 @@ let package = Package(
.target(
name: "Scyther",
dependencies: [
"SnapKit",
"LogInterface"
],
resources: [
Expand Down
102 changes: 75 additions & 27 deletions Sources/Scyther/Components/Cells/DeviceCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,93 @@
// Created by Brandon Stillitano on 16/12/20.
//

#if !os(macOS)
import UIKit

final internal class DeviceTableViewCell: UITableViewCell {
// MARK: - Constraints
var imageViewConstraints: [NSLayoutConstraint] = []
var textLabelConstraints: [NSLayoutConstraint] = []
var detailTextLabelConstraints: [NSLayoutConstraint] = []

// MARK: - Lifecycle
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)

imageView?.layer.cornerRadius = 12.0
imageView?.layer.masksToBounds = true

imageView?.snp.remakeConstraints({ (make) in
make.top.equalToSuperview().inset(8)
make.bottom.equalToSuperview()
make.left.equalToSuperview().inset(16)
make.width.equalTo(48)
make.height.equalTo(48)
})

textLabel?.snp.remakeConstraints({ (make) in
make.bottom.equalTo(imageView?.snp.centerY ?? 0)
make.left.equalTo(imageView?.snp.right ?? 0).offset(16)
make.right.equalToSuperview()
})

detailTextLabel?.snp.remakeConstraints({ (make) in
make.top.equalTo(imageView?.snp.centerY ?? 0)
make.left.equalTo(imageView?.snp.right ?? 0).offset(16)
make.right.equalToSuperview()
})
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
setupConstraints()
}

override func layoutSubviews() {
super.layoutSubviews()
private func setupConstraints() {
// Set Translations
imageView?.translatesAutoresizingMaskIntoConstraints = false
textLabel?.translatesAutoresizingMaskIntoConstraints = false
detailTextLabel?.translatesAutoresizingMaskIntoConstraints = false

// Remove Default Constraints
NSLayoutConstraint.deactivate(imageView?.constraints ?? [])
NSLayoutConstraint.deactivate(textLabel?.constraints ?? [])
NSLayoutConstraint.deactivate(detailTextLabel?.constraints ?? [])

// Clear Existing Constraints
NSLayoutConstraint.deactivate(imageViewConstraints)
NSLayoutConstraint.deactivate(textLabelConstraints)
NSLayoutConstraint.deactivate(detailTextLabelConstraints)
imageViewConstraints.removeAll()
textLabelConstraints.removeAll()
detailTextLabelConstraints.removeAll()

// Setup Image View Constraints
imageViewConstraints.append(imageView?
.topAnchor
.constraint(equalTo: topAnchor,
constant: 8) ?? NSLayoutConstraint())
imageViewConstraints.append(imageView?
.bottomAnchor
.constraint(lessThanOrEqualTo: bottomAnchor) ?? NSLayoutConstraint())
imageViewConstraints.append(imageView?
.leadingAnchor
.constraint(equalTo: leadingAnchor,
constant: 16) ?? NSLayoutConstraint())
imageViewConstraints.append(imageView?
.widthAnchor
.constraint(equalToConstant: 48) ?? NSLayoutConstraint())
imageViewConstraints.append(imageView?
.heightAnchor
.constraint(equalToConstant: 48) ?? NSLayoutConstraint())

// Setup Text Label Constraints
textLabelConstraints.append(textLabel?
.bottomAnchor
.constraint(equalTo: imageView?.centerYAnchor ?? centerYAnchor) ?? NSLayoutConstraint())
textLabelConstraints.append(textLabel?
.leadingAnchor
.constraint(equalTo: imageView?.trailingAnchor ?? leadingAnchor,
constant: 16) ?? NSLayoutConstraint())
textLabelConstraints.append(textLabel?
.trailingAnchor
.constraint(equalTo: trailingAnchor) ?? NSLayoutConstraint())

// Setup Detail Text Label Constraints
detailTextLabelConstraints.append(detailTextLabel?
.topAnchor
.constraint(equalTo: imageView?.centerYAnchor ?? centerYAnchor) ?? NSLayoutConstraint())
detailTextLabelConstraints.append(detailTextLabel?
.leadingAnchor
.constraint(equalTo: imageView?.trailingAnchor ?? leadingAnchor,
constant: 16) ?? NSLayoutConstraint())
detailTextLabelConstraints.append(detailTextLabel?
.trailingAnchor
.constraint(equalTo: trailingAnchor) ?? NSLayoutConstraint())

// Activate Constraints
NSLayoutConstraint.activate(imageViewConstraints)
NSLayoutConstraint.activate(textLabelConstraints)
NSLayoutConstraint.activate(detailTextLabelConstraints)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
#endif
165 changes: 120 additions & 45 deletions Sources/Scyther/Components/Cells/NetworkLogCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Brandon Stillitano on 25/12/20.
//

#if os(iOS)
import UIKit

class NetworkLogCell: UITableViewCell {
Expand All @@ -16,9 +15,16 @@ class NetworkLogCell: UITableViewCell {
var timeLabel: UILabel = UILabel(frame: .zero)
var urlLabel: UILabel = UILabel(frame: .zero)

// MARK: - Constraints
var statusViewConstraints: [NSLayoutConstraint] = []
var methodLabelConstraints: [NSLayoutConstraint] = []
var responseLabelConstraints: [NSLayoutConstraint] = []
var timeLabelConstraints: [NSLayoutConstraint] = []
var urlLabelConstraints: [NSLayoutConstraint] = []

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

/// Setup UI
setupUI()
setupConstraints()
Expand All @@ -27,7 +33,7 @@ class NetworkLogCell: UITableViewCell {
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupUI() {
/// Setup `statusView`
contentView.addSubview(self.statusView)
Expand All @@ -41,55 +47,125 @@ class NetworkLogCell: UITableViewCell {
methodLabel.textAlignment = .center
methodLabel.font = .boldSystemFont(ofSize: 16)
contentView.addSubview(self.methodLabel)

/// Setup `responseLabel`
responseLabel.textAlignment = .center
contentView.addSubview(responseLabel)

/// Setup `timeLabel`
timeLabel.textAlignment = .center
timeLabel.font = .systemFont(ofSize: 11)
contentView.addSubview(timeLabel)
}

private func setupConstraints() {
/// Setup `statusView` constraints
statusView.snp.remakeConstraints { (make) in
make.top.equalToSuperview()
make.bottom.equalToSuperview()
make.left.equalToSuperview()
make.width.equalTo(8)
}

/// Setup `methodLabel` constraints
methodLabel.snp.remakeConstraints { (make) in
make.top.equalToSuperview().inset(8)
make.left.equalTo(statusView.snp.right).offset(8)
make.width.equalTo(48)
}

/// Setup `responseLabel` constraints
responseLabel.snp.remakeConstraints { (make) in
make.top.greaterThanOrEqualTo(methodLabel.snp.bottom).offset(8)
make.left.equalTo(statusView.snp.right).offset(8)
make.width.equalTo(48)
}

/// Setup `timeLabel` constraints
timeLabel.snp.remakeConstraints { (make) in
make.top.greaterThanOrEqualTo(responseLabel.snp.bottom).offset(8)
make.left.equalTo(statusView.snp.right).offset(8)
make.width.equalTo(48)
make.bottom.equalToSuperview().inset(8)
}

/// Setup `urlLabel` constraints
urlLabel.snp.remakeConstraints { (make) in
make.top.equalToSuperview().inset(8)
make.bottom.equalToSuperview().inset(8)
make.left.equalTo(methodLabel.snp.right).offset(16)
make.right.equalToSuperview().inset(16)
}
// Set Translations
statusView.translatesAutoresizingMaskIntoConstraints = false
methodLabel.translatesAutoresizingMaskIntoConstraints = false
responseLabel.translatesAutoresizingMaskIntoConstraints = false
timeLabel.translatesAutoresizingMaskIntoConstraints = false
urlLabel.translatesAutoresizingMaskIntoConstraints = false

// Remove Default Constraints
NSLayoutConstraint.deactivate(imageView?.constraints ?? [])
NSLayoutConstraint.deactivate(textLabel?.constraints ?? [])
NSLayoutConstraint.deactivate(detailTextLabel?.constraints ?? [])
NSLayoutConstraint.deactivate(textLabel?.constraints ?? [])
NSLayoutConstraint.deactivate(textLabel?.constraints ?? [])

// Clear Existing Constraints
NSLayoutConstraint.deactivate(statusViewConstraints)
NSLayoutConstraint.deactivate(methodLabelConstraints)
NSLayoutConstraint.deactivate(responseLabelConstraints)
NSLayoutConstraint.deactivate(timeLabelConstraints)
NSLayoutConstraint.deactivate(urlLabelConstraints)
statusViewConstraints.removeAll()
methodLabelConstraints.removeAll()
responseLabelConstraints.removeAll()
timeLabelConstraints.removeAll()
urlLabelConstraints.removeAll()

// Setup Status View Constraints
statusViewConstraints.append(statusView
.topAnchor
.constraint(equalTo: contentView.topAnchor))
statusViewConstraints.append(statusView
.bottomAnchor
.constraint(equalTo: contentView.bottomAnchor))
statusViewConstraints.append(statusView
.leadingAnchor
.constraint(equalTo: contentView.leadingAnchor))
statusViewConstraints.append(statusView
.widthAnchor
.constraint(equalToConstant: 8))

// Setup Method Label Constraints
methodLabelConstraints.append(methodLabel
.topAnchor
.constraint(equalTo: contentView.topAnchor,
constant: 8))
methodLabelConstraints.append(methodLabel
.leadingAnchor
.constraint(equalTo: statusView.trailingAnchor,
constant: 8))
methodLabelConstraints.append(methodLabel
.widthAnchor
.constraint(equalToConstant: 48))

// Setup Response Label Constraints
responseLabelConstraints.append(responseLabel
.topAnchor
.constraint(greaterThanOrEqualTo: methodLabel.bottomAnchor,
constant: 8))
responseLabelConstraints.append(responseLabel
.leadingAnchor
.constraint(equalTo: statusView.trailingAnchor,
constant: 8))
responseLabelConstraints.append(responseLabel
.widthAnchor
.constraint(equalToConstant: 48))

// Setup Time Label Constraints
timeLabelConstraints.append(timeLabel
.bottomAnchor
.constraint(equalTo: contentView.bottomAnchor,
constant: -8))
timeLabelConstraints.append(timeLabel
.widthAnchor
.constraint(equalToConstant: 48))
timeLabelConstraints.append(timeLabel
.leadingAnchor
.constraint(equalTo: statusView.trailingAnchor,
constant: 8))
timeLabelConstraints.append(timeLabel
.topAnchor
.constraint(greaterThanOrEqualTo: responseLabel.bottomAnchor,
constant: 8))

// Setup URL Label Constraints
urlLabelConstraints.append(urlLabel
.topAnchor
.constraint(equalTo: contentView.topAnchor,
constant: 8))
urlLabelConstraints.append(urlLabel
.bottomAnchor
.constraint(equalTo: contentView.bottomAnchor,
constant: -8))
urlLabelConstraints.append(urlLabel
.trailingAnchor
.constraint(equalTo: contentView.trailingAnchor,
constant: -16))
urlLabelConstraints.append(urlLabel
.leadingAnchor
.constraint(equalTo: methodLabel.trailingAnchor,
constant: 16))

// Activate Constraints
NSLayoutConstraint.activate(statusViewConstraints)
NSLayoutConstraint.activate(methodLabelConstraints)
NSLayoutConstraint.activate(responseLabelConstraints)
NSLayoutConstraint.activate(timeLabelConstraints)
NSLayoutConstraint.activate(urlLabelConstraints)
}

override func layoutSubviews() {
Expand All @@ -105,10 +181,9 @@ class NetworkLogCell: UITableViewCell {
timeLabel.text = row.httpRequestTime
urlLabel.text = row.httpRequestURL
methodLabel.text = row.httpMethod

/// Set Colors
responseLabel.textColor = row.httpStatusColor
statusView.backgroundColor = row.httpStatusColor
}
}
#endif
Loading

0 comments on commit 606ca17

Please sign in to comment.