Skip to content
Closed
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
11 changes: 11 additions & 0 deletions examples/SocialAppLayoutSwift/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'SocialAppLayoutSwift' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for SocialAppLayoutSwift
pod 'AsyncDisplayKit'

end

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// AppDelegate.swift
// SocialAppLayoutSwift
//
// Created by Dicky Johan on 14/4/17.
// Copyright © 2017 Dicky Johan. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.backgroundColor = UIColor.white
self.window?.rootViewController = UINavigationController.init(rootViewController: ViewController())
self.window?.makeKeyAndVisible()
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// CommentsNode.swift
// SocialAppLayoutSwift
//
// Created by Dicky Johan on 14/4/17.
// Copyright © 2017 Dicky Johan. All rights reserved.
//

import Foundation
import AsyncDisplayKit


class CommentsNode: ASControlNode {

var iconNode:ASImageNode?
var countNode:ASTextNode?
var commentsCount:Int?

init(comentsCount:Int) {
super.init()
self.commentsCount = comentsCount

let iconNode = ASImageNode()
iconNode.image = UIImage(named:"icon_comment.png")
self.addSubnode(iconNode)
self.iconNode = iconNode

let countNode = ASTextNode()
if (self.commentsCount! > 0) {
countNode.attributedText = NSAttributedString(string:String(format:"%zd",comentsCount),attributes:TextStyles.cellControlStyle)
}
self.addSubnode(countNode)
self.countNode = countNode

// make it tappable easily
self.hitTestSlop = UIEdgeInsetsMake(-10, -10, -10, -10)

}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let mainStack = ASStackLayoutSpec.init(direction: .horizontal, spacing: 6.0, justifyContent: .start, alignItems: .center, children: [self.iconNode!, self.countNode!])

// Adjust size
mainStack.style.minWidth = ASDimensionMakeWithPoints(60.0)
mainStack.style.maxHeight = ASDimensionMakeWithPoints(40.0)

return mainStack
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions examples/SocialAppLayoutSwift/SocialAppLayoutSwift/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
59 changes: 59 additions & 0 deletions examples/SocialAppLayoutSwift/SocialAppLayoutSwift/LikesNode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// LikesNode.swift
// SocialAppLayoutSwift
//
// Created by Dicky Johan on 14/4/17.
// Copyright © 2017 Dicky Johan. All rights reserved.
//

import Foundation
import AsyncDisplayKit

class LikesNode : ASControlNode {

var iconNode:ASImageNode?
var countNode:ASTextNode?
var likesCount:Int?
var liked:Bool?

init(likesCount:Int) {
super.init()
self.likesCount = likesCount
self.liked = (likesCount > 0) ? LikesNode.getYesOrNo() : false

let iconNode = ASImageNode()
iconNode.image = UIImage(named:"icon_liked.png")
self.addSubnode(iconNode)
self.iconNode = iconNode

let countNode = ASTextNode()
if (self.likesCount! > 0) {
let attributes = self.liked! ? TextStyles.cellControlColoredStyle : TextStyles.cellControlStyle
countNode.attributedText = NSAttributedString(string:String(format:"%ld",likesCount),attributes:attributes)
}
self.addSubnode(countNode)
self.countNode = countNode

// make it tappable easily
self.hitTestSlop = UIEdgeInsetsMake(-10, -10, -10, -10)

}

static func getYesOrNo() -> Bool {
let tmp = (arc4random() % 30)+1
if (tmp % 5 == 0) {
return true
}
return false
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let mainStack = ASStackLayoutSpec(direction: .horizontal, spacing: 6.0, justifyContent: .start, alignItems: .center, children: [self.iconNode!, self.countNode!])

mainStack.style.minWidth = ASDimensionMakeWithPoints(60.0)
mainStack.style.maxHeight = ASDimensionMakeWithPoints(40.0)

return mainStack
}

}
22 changes: 22 additions & 0 deletions examples/SocialAppLayoutSwift/SocialAppLayoutSwift/Post.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Post.swift
// SocialAppLayoutSwift
//
// Created by Dicky Johan on 14/4/17.
// Copyright © 2017 Dicky Johan. All rights reserved.
//

import Foundation

class Post {
var username:String = ""
var name:String = ""
var photo:String = ""
var post:String = ""
var time:String = ""
var media:String = ""
var via:Int = 0

var likes:Int = 0
var comments:Int = 0
}
Loading