Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions LayoutFrameworkBenchmark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
24661D0A1F4EFFF5002CB883 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 24661D081F4EFFF5002CB883 /* LaunchScreen.storyboard */; };
639E5A2020DF62D700C6BCEA /* NKFrameLayoutKitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 639E5A1F20DF62D700C6BCEA /* NKFrameLayoutKitView.swift */; };
BF3DC69820B560A400536177 /* FeedItemNotAutoLayoutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3DC69720B560A400536177 /* FeedItemNotAutoLayoutView.swift */; };
E4A8A14124FE99B1009D872B /* FeedItemTextureNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4A8A14024FE982E009D872B /* FeedItemTextureNode.swift */; };
E4A8A24F24FEDD14009D872B /* TextureCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4A8A24E24FEDD14009D872B /* TextureCollectionViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -52,6 +54,8 @@
639E5A1F20DF62D700C6BCEA /* NKFrameLayoutKitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NKFrameLayoutKitView.swift; sourceTree = "<group>"; };
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>"; };
BF3DC69720B560A400536177 /* FeedItemNotAutoLayoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedItemNotAutoLayoutView.swift; sourceTree = "<group>"; };
E4A8A14024FE982E009D872B /* FeedItemTextureNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedItemTextureNode.swift; sourceTree = "<group>"; };
E4A8A24E24FEDD14009D872B /* TextureCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextureCollectionViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -69,6 +73,7 @@
2401BC741F4F017D00788998 /* Benchmarks */ = {
isa = PBXGroup;
children = (
E4A8A13F24FE981F009D872B /* Texture */,
2401BCA21F4F045600788998 /* AutoLayout */,
2401BC921F4F020D00788998 /* FlexLayout */,
2401BC8D1F4F01CC00788998 /* LayoutKit */,
Expand Down Expand Up @@ -208,6 +213,15 @@
name = NotAutoLayout;
sourceTree = "<group>";
};
E4A8A13F24FE981F009D872B /* Texture */ = {
isa = PBXGroup;
children = (
E4A8A14024FE982E009D872B /* FeedItemTextureNode.swift */,
E4A8A24E24FEDD14009D872B /* TextureCollectionViewController.swift */,
);
name = Texture;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -289,17 +303,25 @@
"${BUILT_PRODUCTS_DIR}/LayoutKit/LayoutKit.framework",
"${BUILT_PRODUCTS_DIR}/NKFrameLayoutKit/NKFrameLayoutKit.framework",
"${BUILT_PRODUCTS_DIR}/NotAutoLayout/NotAutoLayout.framework",
"${BUILT_PRODUCTS_DIR}/PINCache/PINCache.framework",
"${BUILT_PRODUCTS_DIR}/PINOperation/PINOperation.framework",
"${BUILT_PRODUCTS_DIR}/PINRemoteImage/PINRemoteImage.framework",
"${BUILT_PRODUCTS_DIR}/PinLayout/PinLayout.framework",
"${PODS_ROOT}/Reveal-SDK/RevealServer/iOS/RevealServer.framework",
"${BUILT_PRODUCTS_DIR}/Texture/AsyncDisplayKit.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlexLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LayoutKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/NKFrameLayoutKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/NotAutoLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PINCache.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PINOperation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PINRemoteImage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PinLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RevealServer.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AsyncDisplayKit.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -331,6 +353,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E4A8A24F24FEDD14009D872B /* TextureCollectionViewController.swift in Sources */,
2401BCA11F4F044000788998 /* FeedItemUIStackView.swift in Sources */,
2401BC8B1F4F018C00788998 /* Stopwatch.swift in Sources */,
2401BC8F1F4F01D600788998 /* FeedItemLayoutKitView.swift in Sources */,
Expand All @@ -340,6 +363,7 @@
2401BC821F4F018C00788998 /* CollectionViewController.swift in Sources */,
2401BC9E1F4F042700788998 /* FeedItemManualView.swift in Sources */,
2401BC811F4F018C00788998 /* BenchmarkViewController.swift in Sources */,
E4A8A14124FE99B1009D872B /* FeedItemTextureNode.swift in Sources */,
BF3DC69820B560A400536177 /* FeedItemNotAutoLayoutView.swift in Sources */,
639E5A2020DF62D700C6BCEA /* NKFrameLayoutKitView.swift in Sources */,
2401BC9B1F4F03B300788998 /* ProfileCardLayout.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class BenchmarkViewController: UITableViewController {
return CollectionViewControllerFeedItemPinLayoutView(data: data)
}),

ViewControllerData(title: "Texture", factoryBlock: { viewCount in
let data = FeedItemData.generate(count: viewCount)
return TextureCollectionViewController(data: data)
}),

ViewControllerData(title: "UIStackView", factoryBlock: { viewCount in
if #available(iOS 9.0, *) {
let data = FeedItemData.generate(count: viewCount)
Expand Down
221 changes: 221 additions & 0 deletions LayoutFrameworkBenchmark/FeedItemTextureNode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
// Copyright 2016 LinkedIn Corp.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import UIKit
import AsyncDisplayKit

/// A LinkedIn feed item that is implemented with Texture.
class FeedItemTextureNode: ASCellNode {
let topBarView = TopBarNode()
let miniProfileView = MiniProfileNode()
let miniContentView = MiniContentNode()
let socialActionsView = SocialActionsNode()
let commentView = CommentNode()

init(data: FeedItemData) {
topBarView.actionLabel.attributedText = data.actionText.makeAttributedString()
miniProfileView.posterNameLabel.attributedText = data.posterName.makeAttributedString()
miniProfileView.posterHeadlineLabel.attributedText = data.posterHeadline.makeAttributedString()
miniProfileView.posterTimeLabel.attributedText = data.posterTimestamp.makeAttributedString()
miniProfileView.posterCommentLabel.attributedText = data.posterComment.makeAttributedString()
miniContentView.contentTitleLabel.attributedText = data.contentTitle.makeAttributedString()
miniContentView.contentDomainLabel.attributedText = data.contentDomain.makeAttributedString()
commentView.actorCommentLabel.attributedText = data.actorComment.makeAttributedString()
super.init()
[topBarView, miniProfileView, miniContentView, socialActionsView, commentView].forEach { addSubnode($0) }
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let mainStack = ASStackLayoutSpec(direction: .vertical,
spacing: 0.0,
justifyContent: .spaceBetween,
alignItems: .stretch,
children: [topBarView, miniProfileView, miniContentView, socialActionsView, commentView])
return mainStack
}
}

class CommentNode: ASDisplayNode {
let actorImageView: ASImageNode = {
let i = ASImageNode()
i.image = UIImage(named: "50x50.png")
return i
}()

let actorCommentLabel: ASTextNode = ASTextNode()

override init() {
super.init()
[actorImageView, actorCommentLabel].forEach { addSubnode($0) }
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
actorCommentLabel.style.flexGrow = 1.0
let mainStack = ASStackLayoutSpec(direction: .horizontal,
spacing: 0.0,
justifyContent: .spaceBetween,
alignItems: .start,
children: [actorImageView, actorCommentLabel])
return mainStack
}
}

class MiniContentNode: ASDisplayNode {
let contentImageView: ASImageNode = {
let i = ASImageNode()
i.image = UIImage(named: "350x200.png")
i.contentMode = .scaleAspectFit
i.backgroundColor = UIColor.orange
return i
}()

let contentTitleLabel: ASTextNode = ASTextNode()
let contentDomainLabel: ASTextNode = ASTextNode()

override init() {
super.init()
[contentImageView, contentTitleLabel, contentDomainLabel].forEach { addSubnode($0) }
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let mainStack = ASStackLayoutSpec(direction: .vertical,
spacing: 0.0,
justifyContent: .spaceBetween,
alignItems: .stretch,
children: [contentImageView, contentTitleLabel, contentDomainLabel])
return mainStack
}
}

class MiniProfileNode: ASDisplayNode {
let posterImageView: ASImageNode = {
let i = ASImageNode()
i.image = UIImage(named: "50x50.png")
i.backgroundColor = UIColor.orange
i.contentMode = .center
return i
}()

let posterNameLabel: ASTextNode = {
let l = ASTextNode()
l.backgroundColor = UIColor.yellow
return l
}()

let posterHeadlineLabel: ASTextNode = {
let l = ASTextNode()
l.maximumNumberOfLines = 3
l.backgroundColor = UIColor.yellow
return l
}()

let posterTimeLabel: ASTextNode = {
let l = ASTextNode()
l.backgroundColor = UIColor.yellow
return l
}()

let posterCommentLabel: ASTextNode = ASTextNode()

override init() {
super.init()
[posterNameLabel, posterHeadlineLabel, posterTimeLabel, posterImageView, posterCommentLabel].forEach { addSubnode($0) }
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let textStack = ASStackLayoutSpec(direction: .vertical, spacing: 1.0, justifyContent: .spaceBetween, alignItems: .stretch, children: [posterNameLabel, posterHeadlineLabel, posterTimeLabel])
textStack.style.flexGrow = 1.0

let imageTextStack = ASStackLayoutSpec(direction: .horizontal,
spacing: 2.0,
justifyContent: .spaceBetween,
alignItems: .start,
children: [posterImageView,
textStack])

let mainStack = ASStackLayoutSpec(direction: .vertical,
spacing: 3.0,
justifyContent: .start,
alignItems: .stretch,
children: [imageTextStack,
posterCommentLabel])

let insetStack = ASInsetLayoutSpec(insets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 4.0),
child: mainStack)

return insetStack
}
}

class SocialActionsNode: ASDisplayNode {
let likeLabel: ASTextNode = {
let l = ASTextNode()
l.attributedText = "Like".makeAttributedString()
l.backgroundColor = .green
return l
}()

let commentLabel: ASTextNode = {
let l = ASTextNode()
l.attributedText = "Comment".makeAttributedString()
l.backgroundColor = .green
return l
}()

let shareLabel: ASTextNode = {
let l = ASTextNode()
l.attributedText = "Share".makeAttributedString()
l.backgroundColor = .green
return l
}()

override init() {
super.init()
[likeLabel, commentLabel, shareLabel].forEach { addSubnode($0) }
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let mainStack = ASStackLayoutSpec(direction: .horizontal,
spacing: 0.0,
justifyContent: .spaceBetween,
alignItems: .start,
children: [likeLabel, commentLabel, shareLabel])
return mainStack
}
}

class TopBarNode: ASDisplayNode {
let actionLabel: ASTextNode = ASTextNode()

let optionsLabel: ASTextNode = {
let l = ASTextNode()
l.attributedText = "...".makeAttributedString()
return l
}()

override init() {
super.init()
[actionLabel, optionsLabel].forEach { addSubnode($0) }
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let mainStack = ASStackLayoutSpec(direction: .horizontal,
spacing: 0.0,
justifyContent: .start,
alignItems: .start,
children: [actionLabel, optionsLabel])
actionLabel.style.flexGrow = 1.0
return mainStack
}
}

private extension String {
func makeAttributedString() -> NSAttributedString {
return NSAttributedString(string: self, attributes: [.font: UIFont.systemFont(ofSize: 17.0)])
}
}
49 changes: 49 additions & 0 deletions LayoutFrameworkBenchmark/TextureCollectionViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2016 LinkedIn Corp.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import AsyncDisplayKit

class TextureCollectionViewController: ASDKViewController<ASCollectionNode>, ASCollectionDataSource, ASCollectionDelegate {

let collectionNode: ASCollectionNode
let reuseIdentifier = "cell"
let data: [FeedItemData]
let flowLayout: UICollectionViewFlowLayout

init(data: [FeedItemData]) {
self.data = data
self.flowLayout = UICollectionViewFlowLayout()
self.collectionNode = ASCollectionNode(collectionViewLayout: self.flowLayout)
super.init(node: collectionNode)
collectionNode.delegate = self
collectionNode.dataSource = self
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
collectionNode.reloadData()
}

func numberOfSections(in collectionNode: ASCollectionNode) -> Int {
return 1
}

func collectionNode(_ collectionNode: ASCollectionNode, numberOfItemsInSection section: Int) -> Int {
return data.count
}

func collectionNode(_ collectionNode: ASCollectionNode, nodeForItemAt indexPath: IndexPath) -> ASCellNode {
let cell = FeedItemTextureNode(data: data[indexPath.row])

return cell
}
}
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target 'LayoutFrameworkBenchmark' do
pod 'NotAutoLayout'
pod 'NKFrameLayoutKit'
pod 'PinLayout'
pod 'Texture'

pod 'Reveal-SDK'
end
Expand All @@ -27,4 +28,4 @@ post_install do |installer|
end
end
end
end
end
Loading