Skip to content

Commit

Permalink
Merge pull request #100 from hyperoslo/refactor/remove-cartography
Browse files Browse the repository at this point in the history
Refactor: remove cartography
  • Loading branch information
vadymmarkov committed Feb 7, 2018
2 parents d7793c9 + 82445ae commit 3727388
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 59 deletions.
1 change: 0 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
github "robb/Cartography"
github "hyperoslo/Pages"
1 change: 0 additions & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
github "hyperoslo/Pages" "2.0.2"
github "robb/Cartography" "2.0.0"
4 changes: 2 additions & 2 deletions Example/Parallax/Parallax.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,12 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Parallax/Pods-Parallax-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Cartography/Cartography.framework",
"${BUILT_PRODUCTS_DIR}/Hue/Hue.framework",
"${BUILT_PRODUCTS_DIR}/Pages/Pages.framework",
"${BUILT_PRODUCTS_DIR}/Presentation/Presentation.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cartography.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Hue.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Pages.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Presentation.framework",
Expand Down Expand Up @@ -366,6 +364,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Parallax/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -382,6 +381,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Parallax/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
2 changes: 1 addition & 1 deletion Example/Parallax/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use_frameworks!

platform :ios, '8.0'
platform :ios, '9.0'

pod 'Presentation', path: '../../'
pod 'Hue'
Expand Down
17 changes: 7 additions & 10 deletions Example/Parallax/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
PODS:
- Cartography (2.0.0)
- Hue (2.0.1)
- Hue (3.0.1)
- Pages (2.0.2)
- Presentation (3.1.0):
- Cartography
- Pages
- Presentation (4.1.0):
- Pages (~> 2.0)

DEPENDENCIES:
- Hue
Expand All @@ -15,11 +13,10 @@ EXTERNAL SOURCES:
:path: ../../

SPEC CHECKSUMS:
Cartography: d295eb25ab54bb57eecd8c2f04e9648c850f1281
Hue: 354caec055fdc9d38b5ef33ca2e7224721843baf
Hue: 93e852fa6211ab35922ad8c293f51c43d6c79eb2
Pages: 5564ac6035c48fef7a837049314f57507d263b11
Presentation: 07f001419368d0ece73285f238b1dc3852462f23
Presentation: b717a7e0bff6af8e028998269114a344d5c114e4

PODFILE CHECKSUM: 8a38e1ff9630071a018856bbaebe49be27870e49
PODFILE CHECKSUM: 979718cbe7e3509ed288250a31b6c6036f4f9943

COCOAPODS: 1.3.1
COCOAPODS: 1.4.0
2 changes: 1 addition & 1 deletion Example/Tutorial/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!

platform :ios, '8.0'
platform :ios, '9.0'

pod 'Presentation', path: '../../'
pod 'Hue'
Expand Down
17 changes: 7 additions & 10 deletions Example/Tutorial/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
PODS:
- Cartography (2.0.0)
- Hue (1.2.0)
- Hue (3.0.1)
- Pages (2.0.2)
- Presentation (3.1.0):
- Cartography
- Pages
- Presentation (4.1.0):
- Pages (~> 2.0)

DEPENDENCIES:
- Hue
Expand All @@ -15,11 +13,10 @@ EXTERNAL SOURCES:
:path: ../../

SPEC CHECKSUMS:
Cartography: d295eb25ab54bb57eecd8c2f04e9648c850f1281
Hue: 0705083b7aff40334033373e6293ec1215285ac2
Hue: 93e852fa6211ab35922ad8c293f51c43d6c79eb2
Pages: 5564ac6035c48fef7a837049314f57507d263b11
Presentation: 07f001419368d0ece73285f238b1dc3852462f23
Presentation: b717a7e0bff6af8e028998269114a344d5c114e4

PODFILE CHECKSUM: a2be853ebf7792783dc915c68a50d0f469a3c2ec
PODFILE CHECKSUM: fdf662532b7595886c0398895df5b6e99fbfa147

COCOAPODS: 1.3.1
COCOAPODS: 1.4.0
4 changes: 2 additions & 2 deletions Example/Tutorial/Tutorial.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,12 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Tutorial/Pods-Tutorial-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Cartography/Cartography.framework",
"${BUILT_PRODUCTS_DIR}/Hue/Hue.framework",
"${BUILT_PRODUCTS_DIR}/Pages/Pages.framework",
"${BUILT_PRODUCTS_DIR}/Presentation/Presentation.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cartography.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Hue.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Pages.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Presentation.framework",
Expand Down Expand Up @@ -352,6 +350,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Tutorial/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Tutorial;
Expand All @@ -368,6 +367,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Tutorial/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Tutorial;
Expand Down
3 changes: 1 addition & 2 deletions Presentation.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "Presentation"
s.summary = "Presentation helps you to make tutorials, release notes and animated pages."
s.version = "4.0.0"
s.version = "4.1.0"
s.homepage = "https://github.com/hyperoslo/Presentation"
s.license = 'MIT'
s.author = { "Hyper" => "[email protected]" }
Expand All @@ -13,5 +13,4 @@ Pod::Spec.new do |s|

s.source_files = 'Source/**/*'
s.dependency 'Pages', '~> 2.0'
s.dependency 'Cartography', '~> 2.0'
end
5 changes: 0 additions & 5 deletions Presentation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
D523B0EE1C43AC70001AD1EC /* PresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D523B0E41C43AC70001AD1EC /* PresentationController.swift */; };
D523B0EF1C43AC70001AD1EC /* SlideController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D523B0E51C43AC70001AD1EC /* SlideController.swift */; };
D523B0F21C43AE94001AD1EC /* Pages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D523B0F01C43AE94001AD1EC /* Pages.framework */; };
D523B0F31C43AE94001AD1EC /* Cartography.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D523B0F11C43AE94001AD1EC /* Cartography.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -33,7 +32,6 @@
D523B0E41C43AC70001AD1EC /* PresentationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresentationController.swift; sourceTree = "<group>"; };
D523B0E51C43AC70001AD1EC /* SlideController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlideController.swift; sourceTree = "<group>"; };
D523B0F01C43AE94001AD1EC /* Pages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Pages.framework; path = Carthage/Build/iOS/Pages.framework; sourceTree = "<group>"; };
D523B0F11C43AE94001AD1EC /* Cartography.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cartography.framework; path = Carthage/Build/iOS/Cartography.framework; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -42,7 +40,6 @@
buildActionMask = 2147483647;
files = (
D523B0F21C43AE94001AD1EC /* Pages.framework in Frameworks */,
D523B0F31C43AE94001AD1EC /* Cartography.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -111,7 +108,6 @@
isa = PBXGroup;
children = (
D523B0F01C43AE94001AD1EC /* Pages.framework */,
D523B0F11C43AE94001AD1EC /* Cartography.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -198,7 +194,6 @@
);
inputPaths = (
"$(SRCROOT)/Carthage/Build/iOS/Pages.framework",
"$(SRCROOT)/Carthage/Build/iOS/Cartography.framework",
);
outputPaths = (
);
Expand Down
77 changes: 53 additions & 24 deletions Source/Content.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import UIKit
import Cartography

public final class Content: NSObject {
public var view: UIView
Expand All @@ -12,7 +11,7 @@ public final class Content: NSObject {
}

public private(set) var initialPosition: Position
private let group = ConstraintGroup()
private var constraints = [NSLayoutConstraint]()

public init(view: UIView, position: Position, centered: Bool = true) {
self.view = view
Expand All @@ -22,40 +21,70 @@ public final class Content: NSObject {

super.init()

constrain(view) { [unowned self] view in
view.width == self.view.frame.width
view.height == self.view.frame.height
}
view.translatesAutoresizingMaskIntoConstraints = false
setupSizeConstraints()
}

public func layout() {
guard view.superview != nil else {
guard let superview = view.superview else {
return
}

constrain(view, replace: group) { [unowned self] view in
let x = self.position.left == 0.0
? view.superview!.left * 1.0
: view.superview!.right * self.position.left
let y = self.position.top == 0.0
? view.superview!.top * 1.0
: view.superview!.bottom * self.position.top

if self.centered {
view.centerX == x
view.centerY == y
} else {
view.left == x
view.top == y
}
}

NSLayoutConstraint.deactivate(constraints)

let xAttribute: NSLayoutAttribute = centered ? .centerX : .leading
let yAttribute: NSLayoutAttribute = centered ? .centerY : .top
let xSuperAttribute: NSLayoutAttribute = position.left == 0 ? .leading : .trailing
let ySuperAttribute: NSLayoutAttribute = position.top == 0 ? .top : .bottom
let xMultiplier: CGFloat = position.left == 0 ? 1 : position.left
let yMultiplier: CGFloat = position.top == 0 ? 1 : position.top

constraints = [
NSLayoutConstraint(
item: view,
attribute: xAttribute,
relatedBy: .equal,
toItem: superview,
attribute: xSuperAttribute,
multiplier: xMultiplier,
constant: 0
),
NSLayoutConstraint(
item: view,
attribute: yAttribute,
relatedBy: .equal,
toItem: superview,
attribute: ySuperAttribute,
multiplier: yMultiplier,
constant: 0
)
]

NSLayoutConstraint.activate(constraints)
view.layoutIfNeeded()
}

public func animate() {
view.superview!.layoutIfNeeded()
}

private func setupSizeConstraints() {
makeSizeConstraint(attribute: .width, constant: view.frame.width).isActive = true
makeSizeConstraint(attribute: .height, constant: view.frame.height).isActive = true
}

private func makeSizeConstraint(attribute: NSLayoutAttribute,
constant: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: view,
attribute: attribute,
relatedBy: .equal,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1,
constant: constant
)
}
}

public extension Content {
Expand Down

0 comments on commit 3727388

Please sign in to comment.