Skip to content

Commit 4305fc8

Browse files
committed
Add NKFrameLayoutKit benchmark
1 parent 471d4d5 commit 4305fc8

File tree

10 files changed

+209
-4
lines changed

10 files changed

+209
-4
lines changed

LayoutFrameworkBenchmark.xcodeproj/project.pbxproj

Lines changed: 18 additions & 3 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,6 +287,7 @@
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",
280293
"${PODS_ROOT}/Reveal-SDK/RevealServer-14/iOS/RevealServer.framework",
@@ -283,6 +296,7 @@
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 */,
@@ -462,7 +477,7 @@
462477
buildSettings = {
463478
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
464479
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
465-
DEVELOPMENT_TEAM = 4Q596JWQC5;
480+
DEVELOPMENT_TEAM = 385YL4KG69;
466481
INFOPLIST_FILE = LayoutFrameworkBenchmark/Info.plist;
467482
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
468483
PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.LayoutFrameworkBenchmark;
@@ -479,7 +494,7 @@
479494
buildSettings = {
480495
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
481496
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
482-
DEVELOPMENT_TEAM = 4Q596JWQC5;
497+
DEVELOPMENT_TEAM = 385YL4KG69;
483498
INFOPLIST_FILE = LayoutFrameworkBenchmark/Info.plist;
484499
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
485500
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: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
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+
labels.edgeInsets = UIEdgeInsets(top: 1, left: 2, bottom: 3, right: 4)
97+
98+
let v = NKDoubleFrameLayout(direction: .horizontal, andViews: [self.posterImageView, labels])!
99+
v.leftFrameLayout.contentVerticalAlignment = .center
100+
v.spacing = 1
101+
return v
102+
}()
103+
104+
lazy var actions: NKGridFrameLayout = {
105+
let v = NKGridFrameLayout(direction: .horizontal)! // andViews: [self.likeLabel, self.commentLabel, self.shareLabel]
106+
v.add(withTargetView: self.likeLabel).contentHorizontalAlignment = .left
107+
v.add(withTargetView: self.commentLabel).contentHorizontalAlignment = .center
108+
v.add(withTargetView: self.shareLabel).contentHorizontalAlignment = .right
109+
v.layoutAlignment = .split
110+
return v
111+
}()
112+
113+
lazy var comment: NKDoubleFrameLayout = {
114+
let v = NKDoubleFrameLayout(direction: .horizontal, andViews: [self.actorImageView, self.actorCommentLabel])!
115+
return v
116+
}()
117+
118+
override init(frame: CGRect) {
119+
super.init(frame: frame)
120+
addSubview(actionLabel)
121+
addSubview(optionsLabel)
122+
addSubview(posterImageView)
123+
addSubview(posterNameLabel)
124+
addSubview(posterHeadlineLabel)
125+
addSubview(posterTimeLabel)
126+
addSubview(posterCommentLabel)
127+
addSubview(contentImageView)
128+
addSubview(contentTitleLabel)
129+
addSubview(contentDomainLabel)
130+
addSubview(likeLabel)
131+
addSubview(commentLabel)
132+
addSubview(shareLabel)
133+
addSubview(actorImageView)
134+
addSubview(actorCommentLabel)
135+
backgroundColor = UIColor.white
136+
137+
mainFrameLayout = NKGridFrameLayout(direction: .vertical)
138+
mainFrameLayout.add(topBar)
139+
mainFrameLayout.add(posters)
140+
mainFrameLayout.add(withTargetView: posterCommentLabel)
141+
mainFrameLayout.add(withTargetView: contentImageView)
142+
mainFrameLayout.add(withTargetView: contentTitleLabel)
143+
mainFrameLayout.add(withTargetView: contentDomainLabel)
144+
mainFrameLayout.add(actions)
145+
mainFrameLayout.add(comment)
146+
mainFrameLayout.edgeInsets = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
147+
addSubview(mainFrameLayout)
148+
}
149+
150+
required init?(coder aDecoder: NSCoder) {
151+
fatalError("init(coder:) has not been implemented")
152+
}
153+
154+
func setData(_ data: FeedItemData) {
155+
actionLabel.text = data.actionText
156+
posterNameLabel.text = data.posterName
157+
posterHeadlineLabel.text = data.posterHeadline
158+
posterTimeLabel.text = data.posterTimestamp
159+
posterCommentLabel.text = data.posterComment
160+
contentTitleLabel.text = data.contentTitle
161+
contentDomainLabel.text = data.contentDomain
162+
actorCommentLabel.text = data.actorComment
163+
setNeedsLayout()
164+
}
165+
166+
override func layoutSubviews() {
167+
super.layoutSubviews()
168+
mainFrameLayout.frame = self.bounds
169+
}
170+
171+
override func sizeThatFits(_ size: CGSize) -> CGSize {
172+
return mainFrameLayout.sizeThatFits(size)
173+
}
174+
175+
override var intrinsicContentSize: CGSize {
176+
return mainFrameLayout.sizeThatFits(CGSize(width: frame.width, height: CGFloat.greatestFiniteMagnitude))
177+
}
178+
}
179+

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
PODS:
22
- FlexLayout (1.3.6)
33
- LayoutKit (7.0.2)
4+
- NKFrameLayoutKit (2.0)
45
- NotAutoLayout (3.1.1)
56
- PinLayout (1.7.5)
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:
2427
FlexLayout: bcdde388eaf826cfb6f801c8a507e2dca70412fa
2528
LayoutKit: 183c513f8322f4e22321499e54163864bcdf7d97
29+
NKFrameLayoutKit: e06c8baa8d7a7a107d7201a2f17183f99318d879
2630
NotAutoLayout: 2e6e82146dcb556cb61fcfd638b202639c167e84
2731
PinLayout: d89b8e7107f872c039f15132094bc417aa83271d
2832
Reveal-SDK: 55b5c5545233b680c2f8da734f202acc15d422b7
2933

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

3236
COCOAPODS: 1.5.3

0 commit comments

Comments
 (0)