Skip to content

Commit

Permalink
Remove PureLayout from TestingApp
Browse files Browse the repository at this point in the history
  • Loading branch information
yurii-glia committed Jul 20, 2023
1 parent 88a606e commit 26547eb
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 56 deletions.
10 changes: 10 additions & 0 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
754CC61327E27BE2005676E9 /* Survey.SingleChoiceQuestionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75AF8D0A27DD1DD3009EEE2C /* Survey.SingleChoiceQuestionView.swift */; };
754CC61527E27C42005676E9 /* Survey.Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 754CC61427E27C42005676E9 /* Survey.Checkbox.swift */; };
754CC61627E2816F005676E9 /* Survey.InputQuestionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75AF8D0C27DD464A009EEE2C /* Survey.InputQuestionView.swift */; };
7552DFA42A683A2C0093519B /* Layoutable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75B7BD7F2A39D5A70060794D /* Layoutable.swift */; };
7552DFA52A683A2C0093519B /* Makeable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75940955298D386F008B173A /* Makeable.swift */; };
7552DFA62A683A2C0093519B /* Layout+UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75B7BD7D2A39D5430060794D /* Layout+UIView.swift */; };
7552DFA72A683A2C0093519B /* NSLayoutConstraint+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75940957298D386F008B173A /* NSLayoutConstraint+Extensions.swift */; };
7552DFA82A683A2C0093519B /* UIStackView.Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75940956298D386F008B173A /* UIStackView.Extensions.swift */; };
755D186529A6A4E20009F5E8 /* WelcomeStyle+TitleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D186429A6A4E20009F5E8 /* WelcomeStyle+TitleStyle.swift */; };
755D186729A6A4FA0009F5E8 /* WelcomeStyle+SubtitleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D186629A6A4FA0009F5E8 /* WelcomeStyle+SubtitleStyle.swift */; };
755D186929A6A5270009F5E8 /* WelcomeStyle+CheckMessagesButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D186829A6A5270009F5E8 /* WelcomeStyle+CheckMessagesButtonStyle.swift */; };
Expand Down Expand Up @@ -4450,26 +4455,31 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7552DFA62A683A2C0093519B /* Layout+UIView.swift in Sources */,
1A4AD3D9256FE9D300468BFB /* SettingsTextCell.swift in Sources */,
1A4AD3DC256FF67200468BFB /* SettingsFontCell.swift in Sources */,
AF35DFEF2A507B4C0038BCA7 /* VisitorInfoViewController.HeaderView.swift in Sources */,
7552DFA52A683A2C0093519B /* Makeable.swift in Sources */,
1A205D7F25655CEC003AA3CD /* ViewController.swift in Sources */,
AFD3C52C2A472B7500BC37A9 /* VisitorInfoModel.swift in Sources */,
1A4AD3D6256FE7F800468BFB /* UIColor+Extensions.swift in Sources */,
AF11F30728BE6F0C002ACEB4 /* UIAlertController+Extensions.swift in Sources */,
7552DFA82A683A2C0093519B /* UIStackView.Extensions.swift in Sources */,
AF3BD1DF2A42026D00A7713E /* Command.swift in Sources */,
754313CD2870B1C400C9C1C6 /* UserDefaultsStored.swift in Sources */,
1A205D7B25655CEC003AA3CD /* AppDelegate.swift in Sources */,
AF35DFF32A507D3E0038BCA7 /* UIView+Extensions.swift in Sources */,
C0D2F060299F93EC00803B47 /* PlaybookViewController.swift in Sources */,
754313CB2870A65400C9C1C6 /* SettingsViewController.Props.swift in Sources */,
7552DFA42A683A2C0093519B /* Layoutable.swift in Sources */,
7543141828806AEB00C9C1C6 /* EnvironmentSettingsTextCell.swift in Sources */,
84265E6E29914DDA00D65842 /* ViewController+CallVisualizer.swift in Sources */,
754313CF2870E64600C9C1C6 /* Configuration.Extensions.swift in Sources */,
AF35DFF12A507CA70038BCA7 /* VisitorInfoViewController.Cells.swift in Sources */,
AF3BD1DD2A41D09100A7713E /* VisitorInfoViewController.swift in Sources */,
1A4AD3D1256E92F300468BFB /* SettingsColorCell.swift in Sources */,
1A4AD3CE256E8F5500468BFB /* SettingsCell.swift in Sources */,
7552DFA72A683A2C0093519B /* NSLayoutConstraint+Extensions.swift in Sources */,
6B2BFCE2274297F100B68506 /* SettingsSwitchCell.swift in Sources */,
1A60AFF52567CE1300E53F53 /* SettingsViewController.swift in Sources */,
);
Expand Down
16 changes: 8 additions & 8 deletions GliaWidgets/Sources/Layout/NSLayoutConstraint+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@ import UIKit

extension Array where Element == NSLayoutConstraint {
/// Activates all constraints as a batch from array.
public func activate() {
func activate() {
NSLayoutConstraint.activate(self)
}

/// Deactivates all constraints from array.
public func deactivate() {
func deactivate() {
NSLayoutConstraint.deactivate(self)
}

/// Adds consatraint to array.
public static func += (
/// Adds constraint to array.
static func += (
destination: inout [NSLayoutConstraint],
newConstraint: NSLayoutConstraint
) {
destination.append(newConstraint)
}

/// Returns constraints with specific identifier.
public func constraints(with id: NSLayoutConstraint.Identifier) -> [NSLayoutConstraint] {
func constraints(with id: NSLayoutConstraint.Identifier) -> [NSLayoutConstraint] {
filter { $0.identifier == id.rawValue }
}
}

extension NSLayoutConstraint {
/// Defines constraint identifier names.
public enum Identifier: String {
enum Identifier: String {
case leading, top, trailing, bottom, width, height, greaterThanTop, lessThanBottom
}

/// Sets priority for a constraint.
public func priority(_ newValue: UILayoutPriority) -> Self {
func priority(_ newValue: UILayoutPriority) -> Self {
priority = newValue
return self
}

/// Sets identifier for a constraint.
public func identifier(_ id: Identifier) -> Self {
func identifier(_ id: Identifier) -> Self {
identifier = id.rawValue
return self
}
Expand Down
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def swiftlint
end

target 'TestingApp' do
pod 'PureLayout', '~> 3.1'
end

target 'GliaWidgets' do
Expand Down
6 changes: 1 addition & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ PODS:
- GliaCoreDependency (= 1.2)
- TwilioVoice (= 6.3.1)
- WebRTC-lib (= 96.0.0)
- PureLayout (3.1.9)
- SnapshotTesting (1.9.0)
- SwiftLint (0.52.0)
- TwilioVoice (6.3.1)
Expand All @@ -20,15 +19,13 @@ PODS:
DEPENDENCIES:
- AccessibilitySnapshot (= 0.5.0)
- GliaCoreSDK
- PureLayout (~> 3.1)
- SwiftLint

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- AccessibilitySnapshot
- GliaCoreDependency
- GliaCoreSDK
- PureLayout
- SnapshotTesting
- SwiftLint
- TwilioVoice
Expand All @@ -38,12 +35,11 @@ SPEC CHECKSUMS:
AccessibilitySnapshot: a91e4a69f870188b51f43863d9fc7269d07cdd93
GliaCoreDependency: 87b3897f0d85321ecf77f1faa829211ad527e54d
GliaCoreSDK: d0ea050f43cd67f467ab3362c72266accfd11373
PureLayout: 5fb5e5429519627d60d079ccb1eaa7265ce7cf88
SnapshotTesting: 6141c48b6aa76ead61431ca665c14ab9a066c53b
SwiftLint: 13280e21cdda6786ad908dc6e416afe5acd1fcb7
TwilioVoice: 098a959181d4607921f5822d3c9f13043ea4075b
WebRTC-lib: 508fe02efa0c1a3a8867082a77d24c9be5d29aeb

PODFILE CHECKSUM: 2cff546449bcbd614bd806824f1026486bf6619d
PODFILE CHECKSUM: 7d5082d207510e96493a79de2447e3c505ebb330

COCOAPODS: 1.12.1
12 changes: 8 additions & 4 deletions TestingApp/Settings/Cells/EnvironmentSettingsTextCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ final class EnvironmentSettingsTextCell: SettingsCell {
contentView.addSubview(stackView)
stackView.addArrangedSubview(segmentedControl)
stackView.addArrangedSubview(customEnvironmentUrlTextField)
stackView.autoPinEdge(.left, to: .right, of: titleLabel, withOffset: 10)
stackView.autoPinEdgesToSuperviewEdges(
with: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20),
excludingEdge: .left
stackView.translatesAutoresizingMaskIntoConstraints = false
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }
let insets = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20)
constraints += stackView.layoutInSuperview(edges: .vertical, insets: insets)
constraints += stackView.layoutInSuperview(edges: .trailing, insets: insets)
constraints += stackView.leadingAnchor.constraint(
equalTo: titleLabel.trailingAnchor,
constant: 10
)
}

Expand Down
13 changes: 11 additions & 2 deletions TestingApp/Settings/Cells/SettingsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ class SettingsCell: UITableViewCell {

private func layout() {
contentView.addSubview(titleLabel)
titleLabel.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0),
excludingEdge: .right)
titleLabel.translatesAutoresizingMaskIntoConstraints = false
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }
let insets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0)
constraints += titleLabel.layoutInSuperview(
edges: .vertical,
insets: insets
)
constraints += titleLabel.layoutInSuperview(
edges: .leading,
insets: insets
)
}
}
40 changes: 29 additions & 11 deletions TestingApp/Settings/Cells/SettingsColorCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,39 @@ class SettingsColorCell: SettingsCell {

private func layout() {
contentView.addSubview(sampleView)
sampleView.autoSetDimensions(to: CGSize(width: 30, height: 30))
sampleView.autoPinEdge(.left, to: .right, of: titleLabel, withOffset: 20, relation: .greaterThanOrEqual)
sampleView.autoAlignAxis(toSuperviewAxis: .horizontal)
sampleView.translatesAutoresizingMaskIntoConstraints = false
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }
constraints += sampleView.match(value: 30)
constraints += sampleView.leadingAnchor.constraint(
greaterThanOrEqualTo: titleLabel.trailingAnchor,
constant: 20
)
constraints += sampleView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor)

contentView.addSubview(rgbTextField)
rgbTextField.autoSetDimension(.width, toSize: 100)
rgbTextField.autoPinEdge(.left, to: .right, of: sampleView, withOffset: 10)
rgbTextField.autoPinEdge(toSuperviewEdge: .top, withInset: 10)
rgbTextField.autoPinEdge(toSuperviewEdge: .bottom, withInset: 10)
rgbTextField.translatesAutoresizingMaskIntoConstraints = false
constraints += rgbTextField.match(.width, value: 100)
constraints += rgbTextField.layoutInSuperview(
edges: .vertical,
insets: .init(top: 10, left: 0, bottom: 10, right: 0)
)
constraints += rgbTextField.leadingAnchor.constraint(
equalTo: sampleView.trailingAnchor,
constant: 10
)

contentView.addSubview(alphaTextField)
alphaTextField.autoSetDimension(.width, toSize: 50)
alphaTextField.autoAlignAxis(toSuperviewAxis: .horizontal)
alphaTextField.autoPinEdge(.left, to: .right, of: rgbTextField, withOffset: 10)
alphaTextField.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20), excludingEdge: .left)
alphaTextField.translatesAutoresizingMaskIntoConstraints = false
constraints += alphaTextField.match(.width, value: 50)
constraints += alphaTextField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor)
constraints += alphaTextField.leadingAnchor.constraint(
equalTo: rgbTextField.trailingAnchor,
constant: 10
)
constraints += alphaTextField.layoutInSuperview(
edges: .trailing,
insets: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20)
)
}

@objc private func updateSample() {
Expand Down
14 changes: 10 additions & 4 deletions TestingApp/Settings/Cells/SettingsFontCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ class SettingsFontCell: SettingsCell {

private func layout() {
contentView.addSubview(pickerView)
pickerView.autoSetDimensions(to: CGSize(width: 230, height: 100))
pickerView.autoPinEdge(.left, to: .right, of: titleLabel, withOffset: 10)
pickerView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20),
excludingEdge: .left)
pickerView.translatesAutoresizingMaskIntoConstraints = false
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }
constraints += pickerView.match(value: 240)
constraints += pickerView.leadingAnchor.constraint(
equalTo: titleLabel.trailingAnchor,
constant: 10
)
let insets = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20)
constraints += pickerView.layoutInSuperview(edges: .vertical, insets: insets)
constraints += pickerView.layoutInSuperview(edges: .trailing, insets: insets)
}

private func selectDefaultFont() {
Expand Down
24 changes: 18 additions & 6 deletions TestingApp/Settings/Cells/SettingsSwitchCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ final class SettingsSwitchCell: SettingsCell {

private func layout() {
contentView.addSubview(switcher)
switcher.autoPinEdge(.left, to: .right, of: titleLabel, withOffset: 10, relation: .greaterThanOrEqual)
switcher.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20),
excludingEdge: .left)
switcher.translatesAutoresizingMaskIntoConstraints = false
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }
let insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 20)
constraints += switcher.layoutInSuperview(edges: .vertical, insets: insets)
constraints += switcher.layoutInSuperview(edges: .trailing, insets: insets)
constraints += switcher.leadingAnchor.constraint(
equalTo: titleLabel.trailingAnchor,
constant: 10
)
}
}

Expand All @@ -28,8 +34,14 @@ final class SettingsSegmentedCell: SettingsCell {

private func layout() {
contentView.addSubview(segmentedControl)
segmentedControl.autoPinEdge(.left, to: .right, of: titleLabel, withOffset: 10, relation: .greaterThanOrEqual)
segmentedControl.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20),
excludingEdge: .left)
segmentedControl.translatesAutoresizingMaskIntoConstraints = false
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }
let insets = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20)
constraints += segmentedControl.layoutInSuperview(edges: .vertical, insets: insets)
constraints += segmentedControl.layoutInSuperview(edges: .trailing, insets: insets)
constraints += segmentedControl.leadingAnchor.constraint(
equalTo: titleLabel.trailingAnchor,
constant: 10
)
}
}
14 changes: 10 additions & 4 deletions TestingApp/Settings/Cells/SettingsTextCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ class SettingsTextCell: SettingsCell {

private func layout() {
contentView.addSubview(textField)
textField.autoMatch(.width, to: .width, of: contentView, withMultiplier: 0.7)
textField.autoPinEdge(.left, to: .right, of: titleLabel, withOffset: 10, relation: .greaterThanOrEqual)
textField.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20),
excludingEdge: .left)
textField.translatesAutoresizingMaskIntoConstraints = false
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }
constraints += textField.widthAnchor.constraint(
equalTo: contentView.widthAnchor,
multiplier: 0.7
)
constraints += textField.leadingAnchor.constraint(greaterThanOrEqualTo: titleLabel.trailingAnchor, constant: 10)
let insets = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 20)
constraints += textField.layoutInSuperview(edges: .vertical, insets: insets)
constraints += textField.layoutInSuperview(edges: .trailing, insets: insets)
}
}
2 changes: 1 addition & 1 deletion TestingApp/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class SettingsViewController: UIViewController {
tableView.estimatedRowHeight = 50

view.addSubview(tableView)
tableView.autoPinEdgesToSuperviewSafeArea()
tableView.layoutIn(view.safeAreaLayoutGuide).activate()

createCells()
updateConfigurationSection()
Expand Down
12 changes: 2 additions & 10 deletions TestingApp/ViewController/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import UIKit
import PureLayout
import GliaWidgets
import GliaCoreSDK
import GliaWidgets
import UIKit

class ViewController: UIViewController {
typealias Authentication = GliaWidgets.Glia.Authentication
Expand Down Expand Up @@ -174,12 +173,6 @@ extension ViewController {
}

func presentGlia(_ engagementKind: EngagementKind) throws {
let visitorContext: GliaCoreSDK.VisitorContext? = configuration.visitorContext
.map(\.assetId)
.map(GliaCoreSDK.VisitorContext.AssetId.init(rawValue:))
.map(GliaCoreSDK.VisitorContext.ContextType.assetId)
.map(GliaCoreSDK.VisitorContext.init)

Glia.sharedInstance.onEvent = { event in
switch event {
case .started:
Expand Down Expand Up @@ -431,7 +424,6 @@ extension ViewController {
self?.alert(message: error.reason)
}
}

}

let isEmptyJwt = { enteredJwt.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
Expand Down

0 comments on commit 26547eb

Please sign in to comment.