From 26547ebed40bbf85f94d87940da782770adbf291 Mon Sep 17 00:00:00 2001 From: Yurii Dukhovnyi Date: Wed, 19 Jul 2023 18:58:28 +0300 Subject: [PATCH] Remove PureLayout from TestingApp --- GliaWidgets.xcodeproj/project.pbxproj | 10 +++++ .../NSLayoutConstraint+Extensions.swift | 16 ++++---- Podfile | 1 - Podfile.lock | 6 +-- .../Cells/EnvironmentSettingsTextCell.swift | 12 ++++-- TestingApp/Settings/Cells/SettingsCell.swift | 13 +++++- .../Settings/Cells/SettingsColorCell.swift | 40 ++++++++++++++----- .../Settings/Cells/SettingsFontCell.swift | 14 +++++-- .../Settings/Cells/SettingsSwitchCell.swift | 24 ++++++++--- .../Settings/Cells/SettingsTextCell.swift | 14 +++++-- .../Settings/SettingsViewController.swift | 2 +- .../ViewController/ViewController.swift | 12 +----- 12 files changed, 108 insertions(+), 56 deletions(-) diff --git a/GliaWidgets.xcodeproj/project.pbxproj b/GliaWidgets.xcodeproj/project.pbxproj index ee6e962a2..ed9970171 100644 --- a/GliaWidgets.xcodeproj/project.pbxproj +++ b/GliaWidgets.xcodeproj/project.pbxproj @@ -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 */; }; @@ -4450,19 +4455,23 @@ 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 */, @@ -4470,6 +4479,7 @@ 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 */, ); diff --git a/GliaWidgets/Sources/Layout/NSLayoutConstraint+Extensions.swift b/GliaWidgets/Sources/Layout/NSLayoutConstraint+Extensions.swift index 3231910f3..5e88c84c7 100644 --- a/GliaWidgets/Sources/Layout/NSLayoutConstraint+Extensions.swift +++ b/GliaWidgets/Sources/Layout/NSLayoutConstraint+Extensions.swift @@ -2,17 +2,17 @@ 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 ) { @@ -20,25 +20,25 @@ extension Array where Element == NSLayoutConstraint { } /// 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 } diff --git a/Podfile b/Podfile index 80ab50c0e..29a5e98f8 100644 --- a/Podfile +++ b/Podfile @@ -13,7 +13,6 @@ def swiftlint end target 'TestingApp' do - pod 'PureLayout', '~> 3.1' end target 'GliaWidgets' do diff --git a/Podfile.lock b/Podfile.lock index 231a6c38e..9c2510678 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -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) @@ -20,7 +19,6 @@ PODS: DEPENDENCIES: - AccessibilitySnapshot (= 0.5.0) - GliaCoreSDK - - PureLayout (~> 3.1) - SwiftLint SPEC REPOS: @@ -28,7 +26,6 @@ SPEC REPOS: - AccessibilitySnapshot - GliaCoreDependency - GliaCoreSDK - - PureLayout - SnapshotTesting - SwiftLint - TwilioVoice @@ -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 diff --git a/TestingApp/Settings/Cells/EnvironmentSettingsTextCell.swift b/TestingApp/Settings/Cells/EnvironmentSettingsTextCell.swift index 6748042c1..2579772a6 100644 --- a/TestingApp/Settings/Cells/EnvironmentSettingsTextCell.swift +++ b/TestingApp/Settings/Cells/EnvironmentSettingsTextCell.swift @@ -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 ) } diff --git a/TestingApp/Settings/Cells/SettingsCell.swift b/TestingApp/Settings/Cells/SettingsCell.swift index 8791f66dc..bae3e11a5 100644 --- a/TestingApp/Settings/Cells/SettingsCell.swift +++ b/TestingApp/Settings/Cells/SettingsCell.swift @@ -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 + ) } } diff --git a/TestingApp/Settings/Cells/SettingsColorCell.swift b/TestingApp/Settings/Cells/SettingsColorCell.swift index 3b96e1a12..0fd3d56e6 100644 --- a/TestingApp/Settings/Cells/SettingsColorCell.swift +++ b/TestingApp/Settings/Cells/SettingsColorCell.swift @@ -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() { diff --git a/TestingApp/Settings/Cells/SettingsFontCell.swift b/TestingApp/Settings/Cells/SettingsFontCell.swift index 9161eed99..d094b9820 100644 --- a/TestingApp/Settings/Cells/SettingsFontCell.swift +++ b/TestingApp/Settings/Cells/SettingsFontCell.swift @@ -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() { diff --git a/TestingApp/Settings/Cells/SettingsSwitchCell.swift b/TestingApp/Settings/Cells/SettingsSwitchCell.swift index 9fb44257e..bb2ec13fa 100644 --- a/TestingApp/Settings/Cells/SettingsSwitchCell.swift +++ b/TestingApp/Settings/Cells/SettingsSwitchCell.swift @@ -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 + ) } } @@ -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 + ) } } diff --git a/TestingApp/Settings/Cells/SettingsTextCell.swift b/TestingApp/Settings/Cells/SettingsTextCell.swift index a2d2aebb4..71cc3f92f 100644 --- a/TestingApp/Settings/Cells/SettingsTextCell.swift +++ b/TestingApp/Settings/Cells/SettingsTextCell.swift @@ -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) } } diff --git a/TestingApp/Settings/SettingsViewController.swift b/TestingApp/Settings/SettingsViewController.swift index 418186c85..b240e0a3d 100644 --- a/TestingApp/Settings/SettingsViewController.swift +++ b/TestingApp/Settings/SettingsViewController.swift @@ -71,7 +71,7 @@ final class SettingsViewController: UIViewController { tableView.estimatedRowHeight = 50 view.addSubview(tableView) - tableView.autoPinEdgesToSuperviewSafeArea() + tableView.layoutIn(view.safeAreaLayoutGuide).activate() createCells() updateConfigurationSection() diff --git a/TestingApp/ViewController/ViewController.swift b/TestingApp/ViewController/ViewController.swift index f97b6f0a4..4a160f539 100644 --- a/TestingApp/ViewController/ViewController.swift +++ b/TestingApp/ViewController/ViewController.swift @@ -1,7 +1,6 @@ -import UIKit -import PureLayout -import GliaWidgets import GliaCoreSDK +import GliaWidgets +import UIKit class ViewController: UIViewController { typealias Authentication = GliaWidgets.Glia.Authentication @@ -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: @@ -431,7 +424,6 @@ extension ViewController { self?.alert(message: error.reason) } } - } let isEmptyJwt = { enteredJwt.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }