Skip to content

Commit 53643d2

Browse files
authored
Merge pull request #13 from kennic/master
Added NKFrameLayoutKit benchmark (updated)
2 parents 5ad2565 + 1d4e9cd commit 53643d2

File tree

15 files changed

+211
-9
lines changed

15 files changed

+211
-9
lines changed

LayoutFrameworkBenchmark.xcodeproj/project.pbxproj

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
24661D001F4EFFF5002CB883 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24661CFF1F4EFFF5002CB883 /* AppDelegate.swift */; };
2525
24661D071F4EFFF5002CB883 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 24661D061F4EFFF5002CB883 /* Assets.xcassets */; };
2626
24661D0A1F4EFFF5002CB883 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 24661D081F4EFFF5002CB883 /* LaunchScreen.storyboard */; };
27+
639E5A2020DF62D700C6BCEA /* NKFrameLayoutKitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 639E5A1F20DF62D700C6BCEA /* NKFrameLayoutKitView.swift */; };
2728
BF3DC69820B560A400536177 /* FeedItemNotAutoLayoutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3DC69720B560A400536177 /* FeedItemNotAutoLayoutView.swift */; };
2829
/* End PBXBuildFile section */
2930

@@ -48,6 +49,7 @@
4849
24661D091F4EFFF5002CB883 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
4950
24661D0B1F4EFFF5002CB883 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5051
4F34489CA12B845548D7F17E /* Pods_LayoutFrameworkBenchmark.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LayoutFrameworkBenchmark.framework; sourceTree = BUILT_PRODUCTS_DIR; };
52+
639E5A1F20DF62D700C6BCEA /* NKFrameLayoutKitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NKFrameLayoutKitView.swift; sourceTree = "<group>"; };
5153
73BD901DE3512A23A7603899 /* Pods-LayoutFrameworkBenchmark.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LayoutFrameworkBenchmark.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LayoutFrameworkBenchmark/Pods-LayoutFrameworkBenchmark.debug.xcconfig"; sourceTree = "<group>"; };
5254
BF3DC69720B560A400536177 /* FeedItemNotAutoLayoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedItemNotAutoLayoutView.swift; sourceTree = "<group>"; };
5355
/* End PBXFileReference section */
@@ -74,6 +76,7 @@
7476
BF3DC69620B5608000536177 /* NotAutoLayout */,
7577
2401BC911F4F020600788998 /* PinLayout */,
7678
2401BC9F1F4F043800788998 /* UIStackView */,
79+
639E5A1E20DF620D00C6BCEA /* NKFrameLayoutKit */,
7780
2401BC751F4F018C00788998 /* BenchmarkViewController.swift */,
7881
2401BC761F4F018C00788998 /* CollectionViewController.swift */,
7982
2401BC771F4F018C00788998 /* DataBinder.swift */,
@@ -171,6 +174,15 @@
171174
path = LayoutFrameworkBenchmark;
172175
sourceTree = "<group>";
173176
};
177+
639E5A1E20DF620D00C6BCEA /* NKFrameLayoutKit */ = {
178+
isa = PBXGroup;
179+
children = (
180+
639E5A1F20DF62D700C6BCEA /* NKFrameLayoutKitView.swift */,
181+
);
182+
name = NKFrameLayoutKit;
183+
path = Benchmarks/NKFrameLayoutKit;
184+
sourceTree = "<group>";
185+
};
174186
768A1E2833724B1530888DF2 /* Pods */ = {
175187
isa = PBXGroup;
176188
children = (
@@ -229,7 +241,7 @@
229241
TargetAttributes = {
230242
24661CFB1F4EFFF5002CB883 = {
231243
CreatedOnToolsVersion = 8.3.2;
232-
DevelopmentTeam = 4Q596JWQC5;
244+
DevelopmentTeam = 385YL4KG69;
233245
LastSwiftMigration = 0920;
234246
ProvisioningStyle = Automatic;
235247
};
@@ -275,14 +287,16 @@
275287
"${SRCROOT}/Pods/Target Support Files/Pods-LayoutFrameworkBenchmark/Pods-LayoutFrameworkBenchmark-frameworks.sh",
276288
"${BUILT_PRODUCTS_DIR}/FlexLayout/FlexLayout.framework",
277289
"${BUILT_PRODUCTS_DIR}/LayoutKit/LayoutKit.framework",
290+
"${BUILT_PRODUCTS_DIR}/NKFrameLayoutKit/NKFrameLayoutKit.framework",
278291
"${BUILT_PRODUCTS_DIR}/NotAutoLayout/NotAutoLayout.framework",
279292
"${BUILT_PRODUCTS_DIR}/PinLayout/PinLayout.framework",
280-
"${PODS_ROOT}/Reveal-SDK/RevealServer-14/iOS/RevealServer.framework",
293+
"${PODS_ROOT}/Reveal-SDK/RevealServer-16/iOS/RevealServer.framework",
281294
);
282295
name = "[CP] Embed Pods Frameworks";
283296
outputPaths = (
284297
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlexLayout.framework",
285298
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LayoutKit.framework",
299+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/NKFrameLayoutKit.framework",
286300
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/NotAutoLayout.framework",
287301
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PinLayout.framework",
288302
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RevealServer.framework",
@@ -327,6 +341,7 @@
327341
2401BC9E1F4F042700788998 /* FeedItemManualView.swift in Sources */,
328342
2401BC811F4F018C00788998 /* BenchmarkViewController.swift in Sources */,
329343
BF3DC69820B560A400536177 /* FeedItemNotAutoLayoutView.swift in Sources */,
344+
639E5A2020DF62D700C6BCEA /* NKFrameLayoutKitView.swift in Sources */,
330345
2401BC9B1F4F03B300788998 /* ProfileCardLayout.swift in Sources */,
331346
2401BC941F4F021F00788998 /* FeedItemFlexLayoutView.swift in Sources */,
332347
2401BCA41F4F045F00788998 /* FeedItemAutoLayoutView.swift in Sources */,
@@ -466,7 +481,7 @@
466481
buildSettings = {
467482
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
468483
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
469-
DEVELOPMENT_TEAM = 4Q596JWQC5;
484+
DEVELOPMENT_TEAM = 385YL4KG69;
470485
INFOPLIST_FILE = LayoutFrameworkBenchmark/Info.plist;
471486
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
472487
PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.LayoutFrameworkBenchmark;
@@ -483,7 +498,7 @@
483498
buildSettings = {
484499
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
485500
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
486-
DEVELOPMENT_TEAM = 4Q596JWQC5;
501+
DEVELOPMENT_TEAM = 385YL4KG69;
487502
INFOPLIST_FILE = LayoutFrameworkBenchmark/Info.plist;
488503
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
489504
PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.LayoutFrameworkBenchmark;

LayoutFrameworkBenchmark.xcodeproj/project.xcworkspace/contents.xcworkspacedata

100644100755
File mode changed.

LayoutFrameworkBenchmark.xcodeproj/project.xcworkspace/xcuserdata/dionlu.xcuserdatad/UserInterfaceState.xcuserstate

100644100755
File mode changed.

LayoutFrameworkBenchmark.xcodeproj/xcshareddata/xcschemes/LayoutFrameworkBenchmark.xcscheme

100644100755
File mode changed.

LayoutFrameworkBenchmark.xcworkspace/contents.xcworkspacedata

100644100755
File mode changed.

LayoutFrameworkBenchmark/Benchmarks/BenchmarkViewController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class BenchmarkViewController: UITableViewController {
3838
let data = FeedItemData.generate(count: viewCount)
3939
return CollectionViewControllerFeedItemManualView(data: data)
4040
}),
41+
42+
ViewControllerData(title: "NKFrameLayoutKit", factoryBlock: { viewCount in
43+
let data = FeedItemData.generate(count: viewCount)
44+
return CollectionViewControllerFeedItemNKFrameLayoutKitView(data: data)
45+
}),
4146

4247
ViewControllerData(title: "NotAutoLayout", factoryBlock: { viewCount in
4348
let data = FeedItemData.generate(count: viewCount)

LayoutFrameworkBenchmark/Benchmarks/CollectionViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CollectionViewControllerFeedItemManualView: CollectionViewController<FeedI
2828
class CollectionViewControllerFeedItemNotAutoLayoutView: CollectionViewController<FeedItemNotAutoLayoutView> {}
2929
class CollectionViewControllerFeedItemPinLayoutView: CollectionViewController<FeedItemPinLayoutView> {}
3030
class CollectionViewControllerFeedItemFlexLayoutView: CollectionViewController<FeedItemFlexLayoutView> {}
31+
class CollectionViewControllerFeedItemNKFrameLayoutKitView: CollectionViewController<NKFrameLayoutKitView> {}
3132

3233
/// A UICollectionView controller where each cell's content view is a DataBinder.
3334
class CollectionViewController<ContentViewType: UIView>: UICollectionViewController, UICollectionViewDelegateFlowLayout where ContentViewType: DataBinder {
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
//
2+
// NKFrameLayoutKitView.swift
3+
// LayoutFrameworkBenchmark
4+
//
5+
// Created by Nam Kennic on 6/24/18.
6+
//
7+
8+
import UIKit
9+
import NKFrameLayoutKit
10+
11+
/// A LinkedIn feed item that is implemented with NKFrameLayoutKit code.
12+
class NKFrameLayoutKitView: UIView, DataBinder {
13+
14+
var mainFrameLayout: NKGridFrameLayout!
15+
16+
let actionLabel: UILabel = {
17+
let l = UILabel()
18+
l.backgroundColor = UIColor.blue
19+
return l
20+
}()
21+
22+
let optionsLabel: UILabel = {
23+
let l = UILabel()
24+
l.text = "..."
25+
return l
26+
}()
27+
28+
let posterImageView: UIImageView = {
29+
let i = UIImageView()
30+
i.image = UIImage(named: "50x50.png")
31+
i.backgroundColor = UIColor.orange
32+
i.contentMode = .scaleToFill
33+
return i
34+
}()
35+
36+
let posterNameLabel: UILabel = UILabel()
37+
38+
let posterHeadlineLabel: UILabel = {
39+
let l = UILabel()
40+
l.numberOfLines = 3
41+
return l
42+
}()
43+
44+
let posterTimeLabel: UILabel = UILabel()
45+
let posterCommentLabel: UILabel = UILabel()
46+
47+
let contentImageView: UIImageView = {
48+
let i = UIImageView()
49+
i.image = UIImage(named: "350x200.png")
50+
i.contentMode = .scaleToFill
51+
return i
52+
}()
53+
54+
let contentTitleLabel: UILabel = UILabel()
55+
let contentDomainLabel: UILabel = UILabel()
56+
57+
let likeLabel: UILabel = {
58+
let l = UILabel()
59+
l.backgroundColor = UIColor(red: 0, green: 0.9, blue: 0, alpha: 1)
60+
l.text = "Like"
61+
return l
62+
}()
63+
64+
let commentLabel: UILabel = {
65+
let l = UILabel()
66+
l.text = "Comment"
67+
l.backgroundColor = UIColor(red: 0, green: 1.0, blue: 0, alpha: 1)
68+
l.textAlignment = .center
69+
return l
70+
}()
71+
72+
let shareLabel: UILabel = {
73+
let l = UILabel()
74+
l.text = "Share"
75+
l.backgroundColor = UIColor(red: 0, green: 0.8, blue: 0, alpha: 1)
76+
l.textAlignment = .right
77+
return l
78+
}()
79+
80+
let actorImageView: UIImageView = {
81+
let i = UIImageView()
82+
i.image = UIImage(named: "50x50.png")
83+
return i
84+
}()
85+
86+
let actorCommentLabel: UILabel = UILabel()
87+
88+
lazy var topBar: NKDoubleFrameLayout = {
89+
let v = NKDoubleFrameLayout(direction: .horizontal, andViews: [self.actionLabel, self.optionsLabel])!
90+
v.rightFrameLayout.contentHorizontalAlignment = .right
91+
return v
92+
}()
93+
94+
lazy var posters: NKDoubleFrameLayout = {
95+
let labels = NKGridFrameLayout(direction: .vertical, andViews: [self.posterNameLabel, self.posterHeadlineLabel, self.posterTimeLabel])!
96+
let v = NKDoubleFrameLayout(direction: .horizontal, andViews: [self.posterImageView, labels])!
97+
v.leftFrameLayout.contentVerticalAlignment = .center
98+
v.spacing = 5
99+
v.edgeInsets = UIEdgeInsets(top: 5, left: 0, bottom: 0, right: 0)
100+
return v
101+
}()
102+
103+
lazy var actions: NKGridFrameLayout = {
104+
let v = NKGridFrameLayout(direction: .horizontal)! // andViews: [self.likeLabel, self.commentLabel, self.shareLabel]
105+
v.add(withTargetView: self.likeLabel).contentHorizontalAlignment = .left
106+
v.add(withTargetView: self.commentLabel).contentHorizontalAlignment = .center
107+
v.add(withTargetView: self.shareLabel).contentHorizontalAlignment = .right
108+
v.layoutAlignment = .split
109+
return v
110+
}()
111+
112+
lazy var comment: NKDoubleFrameLayout = {
113+
let v = NKDoubleFrameLayout(direction: .horizontal, andViews: [self.actorImageView, self.actorCommentLabel])!
114+
v.edgeInsets = UIEdgeInsets(top: 5, left: 0, bottom: 0, right: 0)
115+
v.spacing = 5
116+
return v
117+
}()
118+
119+
override init(frame: CGRect) {
120+
super.init(frame: frame)
121+
addSubview(actionLabel)
122+
addSubview(optionsLabel)
123+
addSubview(posterImageView)
124+
addSubview(posterNameLabel)
125+
addSubview(posterHeadlineLabel)
126+
addSubview(posterTimeLabel)
127+
addSubview(posterCommentLabel)
128+
addSubview(contentImageView)
129+
addSubview(contentTitleLabel)
130+
addSubview(contentDomainLabel)
131+
addSubview(likeLabel)
132+
addSubview(commentLabel)
133+
addSubview(shareLabel)
134+
addSubview(actorImageView)
135+
addSubview(actorCommentLabel)
136+
backgroundColor = UIColor.white
137+
138+
mainFrameLayout = NKGridFrameLayout(direction: .vertical, andViews: [topBar, posters, posterCommentLabel, contentImageView, contentTitleLabel, contentDomainLabel, actions, comment])
139+
mainFrameLayout.edgeInsets = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
140+
addSubview(mainFrameLayout)
141+
}
142+
143+
required init?(coder aDecoder: NSCoder) {
144+
fatalError("init(coder:) has not been implemented")
145+
}
146+
147+
func setData(_ data: FeedItemData) {
148+
actionLabel.text = data.actionText
149+
posterNameLabel.text = data.posterName
150+
posterHeadlineLabel.text = data.posterHeadline
151+
posterTimeLabel.text = data.posterTimestamp
152+
posterCommentLabel.text = data.posterComment
153+
contentTitleLabel.text = data.contentTitle
154+
contentDomainLabel.text = data.contentDomain
155+
actorCommentLabel.text = data.actorComment
156+
setNeedsLayout()
157+
}
158+
159+
override func layoutSubviews() {
160+
super.layoutSubviews()
161+
mainFrameLayout.frame = self.bounds
162+
}
163+
164+
override func sizeThatFits(_ size: CGSize) -> CGSize {
165+
return mainFrameLayout.sizeThatFits(size)
166+
}
167+
168+
override var intrinsicContentSize: CGSize {
169+
return mainFrameLayout.sizeThatFits(CGSize(width: frame.width, height: CGFloat.greatestFiniteMagnitude))
170+
}
171+
}

Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ target 'LayoutFrameworkBenchmark' do
1414
pod 'PinLayout'
1515
pod 'Reveal-SDK'
1616
pod 'NotAutoLayout'
17+
pod 'NKFrameLayoutKit'
1718
end

Podfile.lock

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
PODS:
2-
- FlexLayout (1.3.6)
3-
- LayoutKit (7.0.2)
2+
- FlexLayout (1.3.9)
3+
- LayoutKit (8.0.1)
4+
- NKFrameLayoutKit (2.1)
45
- NotAutoLayout (3.1.1)
56
- PinLayout (1.7.9)
67
- Reveal-SDK (14)
78

89
DEPENDENCIES:
910
- FlexLayout
1011
- LayoutKit
12+
- NKFrameLayoutKit
1113
- NotAutoLayout
1214
- PinLayout
1315
- Reveal-SDK
@@ -16,17 +18,19 @@ SPEC REPOS:
1618
https://github.com/cocoapods/specs.git:
1719
- FlexLayout
1820
- LayoutKit
21+
- NKFrameLayoutKit
1922
- NotAutoLayout
2023
- PinLayout
2124
- Reveal-SDK
2225

2326
SPEC CHECKSUMS:
24-
FlexLayout: bcdde388eaf826cfb6f801c8a507e2dca70412fa
25-
LayoutKit: 183c513f8322f4e22321499e54163864bcdf7d97
27+
FlexLayout: dbe4b2da72ee63d7145cf32bb5bfba375aeeb9e6
28+
LayoutKit: dab1c2eea7a0bf9d8d755a8a793f87a929768455
29+
NKFrameLayoutKit: 6a2f6ac34f85d495e683ea0f7f1605903a4d3e00
2630
NotAutoLayout: 2e6e82146dcb556cb61fcfd638b202639c167e84
2731
PinLayout: 21ce87a865407a7a3c8a38a326611c476095fedf
2832
Reveal-SDK: 55b5c5545233b680c2f8da734f202acc15d422b7
2933

30-
PODFILE CHECKSUM: 8558b640c2bd1d253536da517991c188d0d44fed
34+
PODFILE CHECKSUM: 9565083f4813952a5a640666616b259832defa8b
3135

3236
COCOAPODS: 1.5.3

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
5050
Layout is done by setting UIView's frame property directly. This implementation comes directly from the LayoutKit benchmark.
5151
[Manual layout benchmark's source code](https://github.com/layoutBox/LayoutFrameworkBenchmark/blob/master/LayoutFrameworkBenchmark/Benchmarks/ManualLayout/FeedItemManualView.swift)
5252

53+
* [**NKFrameLayoutKit**](https://github.com/kennic/NKFrameLayoutKit)
54+
NKFrameLayoutKit is a fast and easy to use layout library
55+
[NKFrameLayoutKit benchmark's source code](https://github.com/layoutBox/LayoutFrameworkBenchmark/blob/master/LayoutFrameworkBenchmark/Benchmarks/NKFrameLayoutKit/NKFrameLayoutKitView.swift)
56+
5357
* [**NotAutoLayout**](https://github.com/el-hoshino/NotAutoLayout)
5458
Layout your views without Auto Layout constraints, in a much more swifty way.
5559
[NotAutoLayout benchmark's source code](https://github.com/layoutBox/LayoutFrameworkBenchmark/blob/master/LayoutFrameworkBenchmark/Benchmarks/NotAutoLayout/FeedItemNotAutoLayoutView.swift)
@@ -80,6 +84,7 @@ Here are the benchmark rendering results to compare visual results:
8084
* [FlexLayout rendering result](docs_markdown/benchmark_result_FlexLayout.png)
8185
* [PinLayout rendering result](docs_markdown/benchmark_result_PinLayout.png)
8286
* [LayoutKit rendering result](docs_markdown/benchmark_result_LayoutKit.png)
87+
* [NKFrameLayoutKit rendering result](docs_markdown/benchmark_result_NKFrameLayoutKit.png)
8388

8489
:pushpin: Some work would be required to adjust the layout so that they all match perfectly.
8590

-16.6 KB
Loading
-20.1 KB
Loading
-17.4 KB
Loading
Loading

0 commit comments

Comments
 (0)