Skip to content

Commit

Permalink
Remove SnapKit dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia3546 committed Sep 1, 2022
1 parent 2d86d05 commit 927978f
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 183 deletions.
15 changes: 9 additions & 6 deletions Example/Source/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import UIKit
import SnapKit
import Fastis

class ViewController: UIViewController {
Expand All @@ -21,6 +20,7 @@ class ViewController: UIViewController {
view.distribution = .fill
view.alignment = .center
view.spacing = 16
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

Expand Down Expand Up @@ -86,11 +86,14 @@ class ViewController: UIViewController {
}

private func configureConstraints() {
self.containerView.snp.makeConstraints { (maker) in
maker.center.equalTo(self.view.safeAreaLayoutGuide)
maker.left.top.greaterThanOrEqualTo(self.view.safeAreaLayoutGuide)
maker.bottom.right.lessThanOrEqualTo(self.view.safeAreaLayoutGuide)
}
NSLayoutConstraint.activate([
self.containerView.centerXAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerXAnchor),
self.containerView.centerYAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerYAnchor),
self.containerView.leftAnchor.constraint(greaterThanOrEqualTo: self.view.safeAreaLayoutGuide.leftAnchor),
self.containerView.topAnchor.constraint(greaterThanOrEqualTo: self.view.safeAreaLayoutGuide.topAnchor),
self.containerView.rightAnchor.constraint(lessThanOrEqualTo: self.view.safeAreaLayoutGuide.rightAnchor),
self.containerView.bottomAnchor.constraint(lessThanOrEqualTo: self.view.safeAreaLayoutGuide.bottomAnchor)
])
}

// MARK: - Actions
Expand Down
1 change: 0 additions & 1 deletion Fastis.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Pod::Spec.new do |s|
"Sources/**/*.swift",
]

s.dependency 'SnapKit', '~> 5.0.0'
s.dependency 'JTAppleCalendar', '~> 8.0.0'
s.dependency 'PrettyCards', '~> 1.0.0'

Expand Down
9 changes: 3 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// swift-tools-version:5.5
//
// SnapKit
//
// Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
//
// Fastis
////
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
Expand Down Expand Up @@ -34,13 +32,12 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/patchthecode/JTAppleCalendar", from: "8.0.3"),
.package(url: "https://github.com/SnapKit/SnapKit", from: "5.0.1"),
.package(url: "https://github.com/ilia3546/PrettyCards", from: "1.0.4")
],
targets: [
.target(
name: "Fastis",
dependencies: ["JTAppleCalendar", "SnapKit", "PrettyCards"],
dependencies: ["JTAppleCalendar", "PrettyCards"],
path: "Sources"
)
],
Expand Down
3 changes: 1 addition & 2 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ let project = Project(
name: .Fastis,
dependencies: [
.target(name: .PrettyCards),
.external(name: .JTAppleCalendar),
.external(name: .SnapKit)
.external(name: .JTAppleCalendar)
]
)
],
Expand Down
55 changes: 34 additions & 21 deletions Sources/Views/Controller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import UIKit
import JTAppleCalendar
import SnapKit

/**
Main controller of Fastis framework. Use it to create and present dade picker
Expand Down Expand Up @@ -79,6 +78,7 @@ open class FastisController<Value: FastisValue>: UIViewController, JTACMonthView

private lazy var calendarView: JTACMonthView = {
let monthView = JTACMonthView()
monthView.translatesAutoresizingMaskIntoConstraints = false
monthView.backgroundColor = self.appearance.backgroundColor
monthView.ibCalendarDelegate = self
monthView.ibCalendarDataSource = self
Expand All @@ -94,12 +94,15 @@ open class FastisController<Value: FastisValue>: UIViewController, JTACMonthView
}()

private lazy var weekView: WeekView = {
return WeekView(config: self.config.weekView)
let view = WeekView(config: self.config.weekView)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

private lazy var currentValueView: CurrentValueView<Value> = {
let view = CurrentValueView<Value>(config: self.config.currentValueView)
view.currentValue = self.value
view.translatesAutoresizingMaskIntoConstraints = false
view.onClear = {
self.value = nil
self.viewConfigs.removeAll()
Expand All @@ -115,6 +118,7 @@ open class FastisController<Value: FastisValue>: UIViewController, JTACMonthView

private lazy var shortcutContainerView: ShortcutContainerView<Value> = {
let view = ShortcutContainerView<Value>(config: self.config.shortcutContainerView, itemConfig: self.config.shortcutItemView, shortcuts: self.shortcuts)
view.translatesAutoresizingMaskIntoConstraints = false
if let value = self.value {
view.selectedShortcut = self.shortcuts.first(where: { $0.isEqual(to: value) })
}
Expand Down Expand Up @@ -283,27 +287,36 @@ open class FastisController<Value: FastisValue>: UIViewController, JTACMonthView
}

private func configureConstraints() {
self.currentValueView.snp.makeConstraints { (maker) in
maker.top.equalTo(self.view.safeAreaLayoutGuide)
maker.left.right.equalToSuperview().inset(12)
}
self.weekView.snp.makeConstraints { (maker) in
maker.top.equalTo(self.currentValueView.snp.bottom)
maker.left.right.equalToSuperview().inset(12)
}
NSLayoutConstraint.activate([
self.currentValueView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
self.currentValueView.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 12),
self.currentValueView.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: -12)
])
NSLayoutConstraint.activate([
self.weekView.topAnchor.constraint(equalTo: self.currentValueView.bottomAnchor),
self.weekView.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 12),
self.weekView.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: -12)
])
if !self.shortcuts.isEmpty {
self.shortcutContainerView.snp.makeConstraints { (maker) in
maker.bottom.left.right.equalToSuperview()
}
NSLayoutConstraint.activate([
self.shortcutContainerView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
self.shortcutContainerView.leftAnchor.constraint(equalTo: self.view.leftAnchor),
self.shortcutContainerView.rightAnchor.constraint(equalTo: self.view.rightAnchor)
])
}
self.calendarView.snp.makeConstraints { (maker) in
maker.top.equalTo(self.weekView.snp.bottom)
maker.left.right.equalToSuperview().inset(16)
if !self.shortcuts.isEmpty {
maker.bottom.equalTo(self.shortcutContainerView.snp.top)
} else {
maker.bottom.equalToSuperview()
}
NSLayoutConstraint.activate([
self.calendarView.topAnchor.constraint(equalTo: self.weekView.bottomAnchor),
self.calendarView.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 16),
self.calendarView.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: -16)
])
if !self.shortcuts.isEmpty {
NSLayoutConstraint.activate([
self.calendarView.bottomAnchor.constraint(equalTo: self.shortcutContainerView.topAnchor)
])
} else {
NSLayoutConstraint.activate([
self.calendarView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
])
}
}

Expand Down
34 changes: 22 additions & 12 deletions Sources/Views/CurrentValueView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import UIKit
import SnapKit

class CurrentValueView<Value: FastisValue>: UIView {

Expand All @@ -18,6 +17,7 @@ class CurrentValueView<Value: FastisValue>: UIView {
label.textColor = self.config.placeholderTextColor
label.text = self.config.placeholderTextForRanges
label.font = self.config.textFont
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()

Expand All @@ -28,12 +28,14 @@ class CurrentValueView<Value: FastisValue>: UIView {
button.tintColor = self.config.clearButtonTintColor
button.alpha = 0
button.isUserInteractionEnabled = false
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()

private lazy var containerView: UIView = {
let view = UIView()
view.backgroundColor = .clear
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

Expand Down Expand Up @@ -85,17 +87,25 @@ class CurrentValueView<Value: FastisValue>: UIView {
}

private func configureConstraints() {
self.clearButton.snp.makeConstraints { (maker) in
maker.right.top.bottom.centerY.equalToSuperview()
}
self.label.snp.makeConstraints { (maker) in
maker.top.bottom.centerX.equalToSuperview()
maker.right.lessThanOrEqualTo(self.clearButton.snp.left)
maker.left.greaterThanOrEqualToSuperview()
}
self.containerView.snp.makeConstraints { (maker) in
maker.edges.equalToSuperview().inset(self.config.insets)
}
NSLayoutConstraint.activate([
self.clearButton.rightAnchor.constraint(equalTo: self.containerView.rightAnchor),
self.clearButton.topAnchor.constraint(equalTo: self.containerView.topAnchor),
self.clearButton.bottomAnchor.constraint(equalTo: self.containerView.bottomAnchor),
self.clearButton.centerYAnchor.constraint(equalTo: self.containerView.centerYAnchor)
])
NSLayoutConstraint.activate([
self.label.topAnchor.constraint(equalTo: self.containerView.topAnchor),
self.label.bottomAnchor.constraint(equalTo: self.containerView.bottomAnchor),
self.label.centerXAnchor.constraint(equalTo: self.containerView.centerXAnchor),
self.label.rightAnchor.constraint(lessThanOrEqualTo: self.clearButton.leftAnchor),
self.label.leftAnchor.constraint(greaterThanOrEqualTo: self.containerView.leftAnchor)
])
NSLayoutConstraint.activate([
self.containerView.topAnchor.constraint(equalTo: self.topAnchor, constant: self.config.insets.top),
self.containerView.leftAnchor.constraint(equalTo: self.leftAnchor, constant: self.config.insets.left),
self.containerView.rightAnchor.constraint(equalTo: self.rightAnchor, constant: -self.config.insets.right),
self.containerView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -self.config.insets.bottom)
])
}

private func updateStateForCurrentValue() {
Expand Down
Loading

0 comments on commit 927978f

Please sign in to comment.