diff --git a/LocoKit Demo App.xcodeproj/project.pbxproj b/LocoKit Demo App.xcodeproj/project.pbxproj index 55effc27..1fffd32f 100644 --- a/LocoKit Demo App.xcodeproj/project.pbxproj +++ b/LocoKit Demo App.xcodeproj/project.pbxproj @@ -289,7 +289,7 @@ ); inputPaths = ( "${SRCROOT}/Pods/Target Support Files/Pods-LocoKit Demo App/Pods-LocoKit Demo App-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/Cartography/Cartography.framework", + "${BUILT_PRODUCTS_DIR}/Anchorage/Anchorage.framework", "${BUILT_PRODUCTS_DIR}/GRDB.swift/GRDB.framework", "${BUILT_PRODUCTS_DIR}/LocoKit/LocoKit.framework", "${PODS_ROOT}/LocoKitCore/LocoKitCore.framework", @@ -298,7 +298,7 @@ ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cartography.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Anchorage.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GRDB.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LocoKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LocoKitCore.framework", diff --git a/LocoKit Demo App/ClassifierView.swift b/LocoKit Demo App/ClassifierView.swift index e83bfef2..995f6616 100644 --- a/LocoKit Demo App/ClassifierView.swift +++ b/LocoKit Demo App/ClassifierView.swift @@ -7,7 +7,7 @@ // import LocoKit -import Cartography +import Anchorage class ClassifierView: UIScrollView { @@ -33,13 +33,11 @@ class ClassifierView: UIScrollView { override func didMoveToSuperview() { addSubview(rows) - constrain(rows, superview!) { rows, superview in - rows.top == rows.superview!.top - rows.bottom == rows.superview!.bottom - 8 - rows.left == rows.superview!.left + 16 - rows.right == rows.superview!.right - 16 - rows.right == superview.right - 16 - } + rows.topAnchor == rows.superview!.topAnchor + rows.bottomAnchor == rows.superview!.bottomAnchor - 8 + rows.leftAnchor == rows.superview!.leftAnchor + 16 + rows.rightAnchor == rows.superview!.rightAnchor - 16 + rows.rightAnchor == superview!.rightAnchor - 16 } func update(sample: LocomotionSample? = nil) { diff --git a/LocoKit Demo App/LocoView.swift b/LocoKit Demo App/LocoView.swift index c5ecef68..96cabdb9 100644 --- a/LocoKit Demo App/LocoView.swift +++ b/LocoKit Demo App/LocoView.swift @@ -7,7 +7,7 @@ // import LocoKit -import Cartography +import Anchorage import CoreLocation class LocoView: UIScrollView { @@ -31,13 +31,11 @@ class LocoView: UIScrollView { override func didMoveToSuperview() { addSubview(rows) - constrain(rows, superview!) { rows, superview in - rows.top == rows.superview!.top - rows.bottom == rows.superview!.bottom - 8 - rows.left == rows.superview!.left + 16 - rows.right == rows.superview!.right - 16 - rows.right == superview.right - 16 - } + rows.topAnchor == rows.superview!.topAnchor + rows.bottomAnchor == rows.superview!.bottomAnchor - 8 + rows.leftAnchor == rows.superview!.leftAnchor + 16 + rows.rightAnchor == rows.superview!.rightAnchor - 16 + rows.rightAnchor == superview!.rightAnchor - 16 } func update(sample: LocomotionSample? = nil) { diff --git a/LocoKit Demo App/LogView.swift b/LocoKit Demo App/LogView.swift index 97a6d702..0eb82190 100644 --- a/LocoKit Demo App/LogView.swift +++ b/LocoKit Demo App/LogView.swift @@ -7,8 +7,8 @@ // import LocoKit +import Anchorage import SwiftNotes -import Cartography class LogView: UIScrollView { @@ -38,13 +38,11 @@ class LogView: UIScrollView { override func didMoveToSuperview() { addSubview(label) - constrain(label, superview!) { rows, superview in - rows.top == rows.superview!.top + 10 - rows.bottom == rows.superview!.bottom - 10 - rows.left == rows.superview!.left + 8 - rows.right == rows.superview!.right - 8 - rows.right == superview.right - 8 - } + label.topAnchor == label.superview!.topAnchor + 10 + label.bottomAnchor == label.superview!.bottomAnchor - 10 + label.leftAnchor == label.superview!.leftAnchor + 8 + label.rightAnchor == label.superview!.rightAnchor - 8 + label.rightAnchor == superview!.rightAnchor - 8 } func update() { diff --git a/LocoKit Demo App/SettingsView.swift b/LocoKit Demo App/SettingsView.swift index d9480d97..ebac9e4d 100644 --- a/LocoKit Demo App/SettingsView.swift +++ b/LocoKit Demo App/SettingsView.swift @@ -7,7 +7,7 @@ // import SwiftNotes -import Cartography +import Anchorage extension NSNotification.Name { public static let settingsChanged = Notification.Name("settingsChanged") @@ -39,13 +39,11 @@ class SettingsView: UIScrollView { override func didMoveToSuperview() { addSubview(rows) - constrain(rows, superview!) { rows, superview in - rows.top == rows.superview!.top - rows.bottom == rows.superview!.bottom - rows.left == rows.superview!.left + 8 - rows.right == rows.superview!.right - 8 - rows.right == superview.right - 8 - } + rows.topAnchor == rows.superview!.topAnchor + rows.bottomAnchor == rows.superview!.bottomAnchor + rows.leftAnchor == rows.superview!.leftAnchor + 8 + rows.rightAnchor == rows.superview!.rightAnchor - 8 + rows.rightAnchor == superview!.rightAnchor - 8 } func buildViewTree() { diff --git a/LocoKit Demo App/TimelineView.swift b/LocoKit Demo App/TimelineView.swift index 5e24144a..1c14b059 100644 --- a/LocoKit Demo App/TimelineView.swift +++ b/LocoKit Demo App/TimelineView.swift @@ -7,7 +7,7 @@ // import LocoKit -import Cartography +import Anchorage class TimelineView: UIScrollView { @@ -32,13 +32,11 @@ class TimelineView: UIScrollView { override func didMoveToSuperview() { addSubview(rows) - constrain(rows, superview!) { rows, superview in - rows.top == rows.superview!.top - rows.bottom == rows.superview!.bottom - 16 - rows.left == rows.superview!.left + 16 - rows.right == rows.superview!.right - 16 - rows.right == superview.right - 16 - } + rows.topAnchor == rows.superview!.topAnchor + rows.bottomAnchor == rows.superview!.bottomAnchor - 16 + rows.leftAnchor == rows.superview!.leftAnchor + 16 + rows.rightAnchor == rows.superview!.rightAnchor - 16 + rows.rightAnchor == superview!.rightAnchor - 16 } func update(with items: [TimelineItem]) { diff --git a/LocoKit Demo App/ToggleBox.swift b/LocoKit Demo App/ToggleBox.swift index c016d65b..25c412f3 100644 --- a/LocoKit Demo App/ToggleBox.swift +++ b/LocoKit Demo App/ToggleBox.swift @@ -6,7 +6,7 @@ // Copyright © 2017 Big Paua. All rights reserved. // -import Cartography +import Anchorage class ToggleBox: UIView { @@ -36,20 +36,14 @@ class ToggleBox: UIView { let dotWidth = dot.frame.size.width addSubview(dot) - constrain(dot) { dot in - dot.centerY == dot.superview!.centerY - dot.height == dotWidth - dot.width == dotWidth - } - + dot.centerYAnchor == dot.superview!.centerYAnchor + dot.heightAnchor == dotWidth + dot.widthAnchor == dotWidth + if let lastDot = lastDot { - constrain(dot, lastDot) { dot, lastDot in - dot.left == lastDot.right - 4 - } + dot.leftAnchor == lastDot.rightAnchor - 4 } else { - constrain(dot) { dot in - dot.left == dot.superview!.left + 8 - } + dot.leftAnchor == dot.superview!.leftAnchor + 8 } lastDot = dot @@ -67,25 +61,19 @@ class ToggleBox: UIView { addSubview(toggle) if let lastDot = lastDot { - constrain(lastDot, label) { dot, label in - label.left == dot.right + 5 - } - + label.leftAnchor == lastDot.rightAnchor + 5 + } else { - constrain(label, toggle) { label, toggle in - label.left == label.superview!.left + 9 - } + label.leftAnchor == label.superview!.leftAnchor + 9 } - constrain(label, toggle) { label, toggle in - label.top == label.superview!.top - label.bottom == label.superview!.bottom - label.height == 44 - - toggle.centerY == toggle.superview!.centerY - toggle.right == toggle.superview!.right - 10 - toggle.left == label.right - } + label.topAnchor == label.superview!.topAnchor + label.bottomAnchor == label.superview!.bottomAnchor + label.heightAnchor == 44 + + toggle.centerYAnchor == toggle.superview!.centerYAnchor + toggle.rightAnchor == toggle.superview!.rightAnchor - 10 + toggle.leftAnchor == label.rightAnchor } @objc func triggerOnChange() { diff --git a/LocoKit Demo App/UIStackView.helpers.swift b/LocoKit Demo App/UIStackView.helpers.swift index f7601bec..d918d119 100644 --- a/LocoKit Demo App/UIStackView.helpers.swift +++ b/LocoKit Demo App/UIStackView.helpers.swift @@ -6,7 +6,7 @@ // Copyright © 2017 Big Paua. All rights reserved. // -import Cartography +import Anchorage extension UIStackView { @@ -14,20 +14,14 @@ extension UIStackView { let underline = UIView() underline.backgroundColor = UIColor(white: 0.85, alpha: 1) addArrangedSubview(underline) - - constrain(underline) { underline in - underline.height == 0.5 - } + underline.heightAnchor == 0.5 } func addGap(height: CGFloat) { let gap = UIView() gap.backgroundColor = .white addArrangedSubview(gap) - - constrain(gap) { gap in - gap.height == height - } + gap.heightAnchor == height } func addHeading(title: String, alignment: NSTextAlignment = .left) { @@ -53,11 +47,7 @@ extension UIStackView { let row = UIStackView() row.distribution = .fillEqually row.spacing = 0.5 - - for view in views { - row.addArrangedSubview(view) - } - + views.forEach { row.addArrangedSubview($0) } addArrangedSubview(row) } @@ -87,12 +77,10 @@ extension UIStackView { row.addArrangedSubview(rightLabel) row.addArrangedSubview(rightPad) addArrangedSubview(row) - - constrain(row, leftPad, rightPad) { row, leftPad, rightPad in - leftPad.width == 8 - rightPad.width == 8 - row.height == 20 - } + + leftPad.widthAnchor == 8 + rightPad.widthAnchor == 8 + row.heightAnchor == 20 return row } diff --git a/LocoKit Demo App/ViewController.swift b/LocoKit Demo App/ViewController.swift index 7ba22051..7da193e2 100644 --- a/LocoKit Demo App/ViewController.swift +++ b/LocoKit Demo App/ViewController.swift @@ -7,8 +7,8 @@ // import LocoKit +import Anchorage import SwiftNotes -import Cartography import CoreLocation class ViewController: UIViewController { @@ -221,39 +221,36 @@ class ViewController: UIViewController { func buildViewTree() { view.addSubview(mapView) - constrain(mapView) { map in - map.top == map.superview!.top - map.left == map.superview!.left - map.right == map.superview!.right - map.height == map.superview!.height * 0.35 - } + mapView.topAnchor == mapView.superview!.topAnchor + mapView.leftAnchor == mapView.superview!.leftAnchor + mapView.rightAnchor == mapView.superview!.rightAnchor + mapView.heightAnchor == mapView.superview!.heightAnchor * 0.35 view.addSubview(topButtons) - constrain(mapView, topButtons) { map, topButtons in - topButtons.top == map.bottom - topButtons.left == topButtons.superview!.left - topButtons.right == topButtons.superview!.right - topButtons.height == 56 - } - + topButtons.topAnchor == mapView.bottomAnchor + topButtons.leftAnchor == topButtons.superview!.leftAnchor + topButtons.rightAnchor == topButtons.superview!.rightAnchor + topButtons.heightAnchor == 56 + topButtons.addSubview(startButton) topButtons.addSubview(stopButton) topButtons.addSubview(clearButton) - constrain(startButton, stopButton, clearButton) { startButton, stopButton, clearButton in - align(top: startButton, stopButton, clearButton) - align(bottom: startButton, stopButton, clearButton) - - startButton.top == startButton.superview!.top - startButton.bottom == startButton.superview!.bottom - 0.5 - startButton.left == startButton.superview!.left - startButton.right == startButton.superview!.centerX + + startButton.topAnchor == stopButton.topAnchor + stopButton.topAnchor == clearButton.topAnchor + startButton.bottomAnchor == stopButton.bottomAnchor + stopButton.bottomAnchor == clearButton.bottomAnchor + + startButton.topAnchor == startButton.superview!.topAnchor + startButton.bottomAnchor == startButton.superview!.bottomAnchor - 0.5 + startButton.leftAnchor == startButton.superview!.leftAnchor + startButton.rightAnchor == startButton.superview!.centerXAnchor - stopButton.edges == startButton.edges + stopButton.edgeAnchors == startButton.edgeAnchors - clearButton.left == startButton.right + 0.5 - clearButton.right == clearButton.superview!.right - } - + clearButton.leftAnchor == startButton.rightAnchor + 0.5 + clearButton.rightAnchor == clearButton.superview!.rightAnchor + view.addSubview(locoView) view.addSubview(classifierView) view.addSubview(logView) @@ -262,28 +259,25 @@ class ViewController: UIViewController { view.addSubview(viewToggleBar) Settings.visibleTab = timelineView - constrain(viewToggleBar) { bar in - bar.bottom == bar.superview!.bottom - bar.left == bar.superview!.left - bar.right == bar.superview!.right - } - - constrain(topButtons, locoView, viewToggleBar) { topButtons, scroller, viewToggleBar in - scroller.top == topButtons.bottom - scroller.left == scroller.superview!.left - scroller.right == scroller.superview!.right - scroller.bottom == viewToggleBar.top - } - - constrain(timelineView, locoView, classifierView, logView, settingsView) { timeline, loco, classifier, log, settings in - settings.edges == loco.edges - timeline.edges == loco.edges - classifier.edges == loco.edges - log.edges == loco.edges - } + viewToggleBar.bottomAnchor == viewToggleBar.superview!.bottomAnchor + viewToggleBar.leftAnchor == viewToggleBar.superview!.leftAnchor + viewToggleBar.rightAnchor == viewToggleBar.superview!.rightAnchor + + locoView.topAnchor == topButtons.bottomAnchor + locoView.leftAnchor == locoView.superview!.leftAnchor + locoView.rightAnchor == locoView.superview!.rightAnchor + locoView.bottomAnchor == viewToggleBar.topAnchor + + settingsView.edgeAnchors == locoView.edgeAnchors + timelineView.edgeAnchors == locoView.edgeAnchors + classifierView.edgeAnchors == locoView.edgeAnchors + logView.edgeAnchors == locoView.edgeAnchors } func update() { + // don't bother updating the UI when we're not in the foreground + guard UIApplication.shared.applicationState == .active else { return } + let items = itemsToShow timelineView.update(with: items) mapView.update(with: items) diff --git a/Podfile b/Podfile index b01b5809..2e75a81e 100644 --- a/Podfile +++ b/Podfile @@ -6,7 +6,7 @@ pod 'LocoKit' pod 'LocoKit/LocalStore' pod 'SwiftNotes' -pod 'Cartography' +pod 'Anchorage' pod 'Fabric' pod 'Crashlytics' diff --git a/Podfile.lock b/Podfile.lock index 893c9d3a..1d52f445 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - Cartography (3.0.1) + - Anchorage (4.2.2) - Crashlytics (3.10.1): - Fabric (~> 1.7.5) - Fabric (1.7.6) @@ -17,7 +17,7 @@ PODS: - Upsurge (0.10.2) DEPENDENCIES: - - Cartography + - Anchorage - Crashlytics - Fabric - LocoKit @@ -26,7 +26,7 @@ DEPENDENCIES: SPEC REPOS: https://github.com/CocoaPods/Specs.git: - - Cartography + - Anchorage - Crashlytics - Fabric - GRDB.swift @@ -36,7 +36,7 @@ SPEC REPOS: - Upsurge SPEC CHECKSUMS: - Cartography: f8c899bb0f5cf20758644a8eea59a75e98a03a5d + Anchorage: cba8707ea6475f604e04047882ba47c07e4b2ac1 Crashlytics: aee1a064cbbf99b32efa3f056a5f458d846bc8ff Fabric: f8d42c893bb187326a7968b62abe55c36a987a46 GRDB.swift: 9859cab1b990eac62ee550d3d2208ec1b44f76af @@ -45,6 +45,6 @@ SPEC CHECKSUMS: SwiftNotes: 51d71568d7515c5c82aa791b88900cf8059b8beb Upsurge: 5866beadc3da27f91c5df4ac795deb3f3238d678 -PODFILE CHECKSUM: dc8799c37620fa788ee1ec5c20ff04d087c4aa4c +PODFILE CHECKSUM: 29ab42a9e3ef069965f0a70a740392b77019d825 COCOAPODS: 1.5.0