Skip to content

Commit d1fdc7e

Browse files
committed
Initial Commit. 🚀
0 parents  commit d1fdc7e

File tree

75 files changed

+3720
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3720
-0
lines changed

.gitignore

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Xcode
2+
#
3+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4+
5+
## Build generated
6+
build/
7+
DerivedData/
8+
9+
## Various settings
10+
*.pbxuser
11+
!default.pbxuser
12+
*.mode1v3
13+
!default.mode1v3
14+
*.mode2v3
15+
!default.mode2v3
16+
*.perspectivev3
17+
!default.perspectivev3
18+
xcuserdata/
19+
20+
## Other
21+
*.moved-aside
22+
*.xccheckout
23+
*.xcscmblueprint
24+
25+
## Obj-C/Swift specific
26+
*.hmap
27+
*.ipa
28+
*.dSYM.zip
29+
*.dSYM
30+
31+
## Playgrounds
32+
timeline.xctimeline
33+
playground.xcworkspace
34+
35+
# Swift Package Manager
36+
#
37+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
38+
# Packages/
39+
# Package.pins
40+
.build/
41+
42+
# CocoaPods
43+
#
44+
# We recommend against adding the Pods directory to your .gitignore. However
45+
# you should judge for yourself, the pros and cons are mentioned at:
46+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
47+
#
48+
# Pods/
49+
50+
# Carthage
51+
#
52+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
53+
# Carthage/Checkouts
54+
55+
Carthage/Build
56+
57+
# fastlane
58+
#
59+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
60+
# screenshots whenever they are needed.
61+
# For more information about the recommended setup visit:
62+
# https://docs.fastlane.tools/best-practices/source-control/#source-control
63+
64+
fastlane/report.xml
65+
fastlane/Preview.html
66+
fastlane/screenshots
67+
fastlane/test_output

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "CoreLayout/infrastructure/vendor/yoga"]
2+
path = CoreLayout/infrastructure/vendor/yoga
3+
url = [email protected]:facebook/yoga.git

CoreLayout.xcodeproj/project.pbxproj

Lines changed: 596 additions & 0 deletions
Large diffs are not rendered by default.

CoreLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0900"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "301AB65C1EB031DD0053C287"
18+
BuildableName = "CoreLayout.framework"
19+
BlueprintName = "CoreLayout"
20+
ReferencedContainer = "container:CoreLayout.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "301AB6A91EB19FCE0053C287"
36+
BuildableName = "CoreLayoutTests.xctest"
37+
BlueprintName = "CoreLayoutTests"
38+
ReferencedContainer = "container:CoreLayout.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "301AB65C1EB031DD0053C287"
46+
BuildableName = "CoreLayout.framework"
47+
BlueprintName = "CoreLayout"
48+
ReferencedContainer = "container:CoreLayout.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
51+
<AdditionalOptions>
52+
</AdditionalOptions>
53+
</TestAction>
54+
<LaunchAction
55+
buildConfiguration = "Debug"
56+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
57+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
58+
launchStyle = "0"
59+
useCustomWorkingDirectory = "NO"
60+
ignoresPersistentStateOnLaunch = "NO"
61+
debugDocumentVersioning = "YES"
62+
debugServiceExtension = "internal"
63+
allowLocationSimulation = "YES">
64+
<MacroExpansion>
65+
<BuildableReference
66+
BuildableIdentifier = "primary"
67+
BlueprintIdentifier = "301AB65C1EB031DD0053C287"
68+
BuildableName = "CoreLayout.framework"
69+
BlueprintName = "CoreLayout"
70+
ReferencedContainer = "container:CoreLayout.xcodeproj">
71+
</BuildableReference>
72+
</MacroExpansion>
73+
<AdditionalOptions>
74+
</AdditionalOptions>
75+
</LaunchAction>
76+
<ProfileAction
77+
buildConfiguration = "Release"
78+
shouldUseLaunchSchemeArgsEnv = "YES"
79+
savedToolIdentifier = ""
80+
useCustomWorkingDirectory = "NO"
81+
debugDocumentVersioning = "YES">
82+
<MacroExpansion>
83+
<BuildableReference
84+
BuildableIdentifier = "primary"
85+
BlueprintIdentifier = "301AB65C1EB031DD0053C287"
86+
BuildableName = "CoreLayout.framework"
87+
BlueprintName = "CoreLayout"
88+
ReferencedContainer = "container:CoreLayout.xcodeproj">
89+
</BuildableReference>
90+
</MacroExpansion>
91+
</ProfileAction>
92+
<AnalyzeAction
93+
buildConfiguration = "Debug">
94+
</AnalyzeAction>
95+
<ArchiveAction
96+
buildConfiguration = "Release"
97+
revealArchiveInOrganizer = "YES">
98+
</ArchiveAction>
99+
</Scheme>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// ComputedLayout+CustomStringConvertible.swift
3+
// Steward
4+
//
5+
// Created by Jake Marsh on 10/2/16.
6+
// Copyright © 2016 Magnus. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
extension ComputedLayout: CustomStringConvertible {
12+
public var description: String {
13+
return description(forDepth: 0)
14+
}
15+
16+
public var debugDescription: String {
17+
return description(forDepth: 0)
18+
}
19+
20+
private func description(forDepth depth: Int) -> String {
21+
let tab = " " // "\t"
22+
23+
let indentation = depth == 0 ? "" : (0...depth).reduce("") { accum, _ in accum + tab }
24+
25+
var d = ""
26+
27+
d += indentation + "ComputedLayout("
28+
29+
if children.count > 0 {
30+
d += "\n" + indentation
31+
d += tab
32+
}
33+
34+
d += "frame: CGRect(x: \(frame.origin.x), y: \(frame.origin.y), width: \(frame.size.width), height: \(frame.size.height))"
35+
36+
if children.count > 0 {
37+
d += ",\n\(indentation + tab)children: ["
38+
39+
d += "\n" + (indentation) + (children.map { $0.description(forDepth: depth + 1) }).joined(separator: ",\n" + indentation)
40+
41+
d += "\n\(indentation + tab)]"
42+
d += "\n\(indentation))"
43+
} else {
44+
d += ")"
45+
}
46+
47+
return d
48+
}
49+
50+
// private func description(forDepth depth: Int) -> String {
51+
// let selfDescription = "{origin={\(frame.origin.x), \(frame.origin.y)}, size={\(frame.size.width), \(frame.size.height)}}"
52+
//
53+
// if children.count > 0 {
54+
// let indentation = (0...depth).reduce("\n") { accum, _ in accum + "\t" }
55+
// let childrenDescription = (children.map { $0.description(forDepth: depth + 1) }).joined(separator: indentation)
56+
// return "\(selfDescription)\(indentation)\(childrenDescription)"
57+
// } else {
58+
// return selfDescription
59+
// }
60+
// }
61+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// ComputedLayout+QuickLook.swift
3+
// CoreLayout
4+
//
5+
// Created by Jake Marsh on 10/2/16.
6+
// Copyright © 2016 Jake Marsh. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
#if os(iOS)
12+
public typealias DebugImageType = UIImage
13+
#elseif os(macOS)
14+
public typealias DebugImageType = NSImage
15+
#endif
16+
17+
extension ComputedLayout {
18+
// @objc
19+
public func debugQuickLookObject() -> UIImage {
20+
return generateQuickLookImage()!
21+
}
22+
23+
public static let debugIdentifierFont = UIFont.monospacedDigitSystemFont(ofSize: 14.0, weight: UIFontWeightSemibold)
24+
25+
public func generateQuickLookImage() -> DebugImageType? {
26+
let drawRect = frame.insetBy(dx: -8, dy: -8)
27+
28+
#if os(iOS)
29+
UIGraphicsBeginImageContextWithOptions(drawRect.size, true, 2.0)
30+
let c = UIGraphicsGetCurrentContext()
31+
32+
let strokeColor = UIColor(red: 0.10, green: 0.41, blue: 1.0, alpha: 1.0)
33+
let fillColor = strokeColor.withAlphaComponent(0.15)
34+
35+
UIColor.white.setFill()
36+
UIRectFill(CGRect(x: 0, y: 0, width: drawRect.size.width, height: drawRect.size.height))
37+
38+
func draw(layout: ComputedLayout, offset: CGPoint) {
39+
let layoutFrame = layout.frame.integral.offsetBy(dx: offset.x, dy: offset.y)
40+
let childOffset = layoutFrame.origin
41+
42+
fillColor.setFill()
43+
UIBezierPath(roundedRect: layoutFrame, cornerRadius: 2).fill()
44+
45+
strokeColor.setStroke()
46+
UIBezierPath(roundedRect: layoutFrame, cornerRadius: 2).stroke()
47+
48+
if let identifier = layout.identifier {
49+
let font = ComputedLayout.debugIdentifierFont
50+
51+
var textRect = layoutFrame
52+
textRect.origin.y = textRect.origin.y + ((textRect.size.height - font.pointSize) / 2)
53+
// textRect.origin.y = 0
54+
55+
let style = NSMutableParagraphStyle()
56+
style.alignment = .center
57+
58+
(identifier as NSString).draw(in: textRect, withAttributes: [
59+
NSParagraphStyleAttributeName : style,
60+
NSFontAttributeName : font,
61+
NSForegroundColorAttributeName : strokeColor
62+
])
63+
}
64+
65+
for child in layout.children {
66+
draw(layout: child, offset: childOffset)
67+
}
68+
}
69+
70+
draw(layout: self, offset: CGPoint(x: 8, y: 8))
71+
72+
let image = UIGraphicsGetImageFromCurrentImageContext()
73+
74+
UIGraphicsEndImageContext()
75+
#elseif os(macOS)
76+
// TODO
77+
#endif
78+
79+
return image
80+
}
81+
}
82+
83+
extension ComputedLayout : CustomPlaygroundQuickLookable {
84+
public var customPlaygroundQuickLook: PlaygroundQuickLook { return .image(generateQuickLookImage()!) }
85+
}

CoreLayout/ComputedLayout.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// ComputedLayout.swift
3+
// CoreLayout
4+
//
5+
// Created by Jake Marsh on 8/8/16.
6+
// Copyright © 2016 Magnus. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct ComputedLayout {
12+
public var identifier: String? = nil
13+
public var frame: CGRect
14+
public let children: [ComputedLayout]
15+
16+
public init(identifier: String? = nil, frame: CGRect, children: [ComputedLayout] = []) {
17+
self.identifier = identifier
18+
self.frame = frame
19+
self.children = children
20+
}
21+
}
22+
23+
extension ComputedLayout : Equatable {
24+
public static func ==(lhs: ComputedLayout, rhs: ComputedLayout) -> Bool {
25+
return lhs.frame == rhs.frame && lhs.children == rhs.children
26+
}
27+
}

0 commit comments

Comments
 (0)