mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Add 'submodules/AsyncDisplayKit/' from commit '02bedc12816e251ad71777f9d2578329b6d2bef6'
git-subtree-dir: submodules/AsyncDisplayKit git-subtree-mainline:d06f423e0egit-subtree-split:02bedc1281
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// Texture
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
||||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
|
||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
|
||||
self.window = window
|
||||
let vc = ViewController()
|
||||
window.rootViewController = UINavigationController(rootViewController: vc)
|
||||
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 throttle down OpenGL ES frame rates. 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 inactive 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:.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<animations/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// DemoCellNode.swift
|
||||
// Texture
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
||||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
|
||||
final class DemoCellNode: ASCellNode {
|
||||
let childA = ASDisplayNode()
|
||||
let childB = ASDisplayNode()
|
||||
var state = State.Right
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
automaticallyManagesSubnodes = true
|
||||
}
|
||||
|
||||
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec {
|
||||
let specA = ASRatioLayoutSpec(ratio: 1, child: childA)
|
||||
specA.style.flexBasis = ASDimensionMakeWithPoints(1)
|
||||
specA.style.flexGrow = 1.0
|
||||
let specB = ASRatioLayoutSpec(ratio: 1, child: childB)
|
||||
specB.style.flexBasis = ASDimensionMakeWithPoints(1)
|
||||
specB.style.flexGrow = 1.0
|
||||
let children = state.isReverse ? [ specB, specA ] : [ specA, specB ]
|
||||
let direction: ASStackLayoutDirection = state.isVertical ? .Vertical : .Horizontal
|
||||
return ASStackLayoutSpec(direction: direction,
|
||||
spacing: 20,
|
||||
justifyContent: .SpaceAround,
|
||||
alignItems: .Center,
|
||||
children: children)
|
||||
}
|
||||
|
||||
override func animateLayoutTransition(context: ASContextTransitioning) {
|
||||
childA.frame = context.initialFrameForNode(childA)
|
||||
childB.frame = context.initialFrameForNode(childB)
|
||||
let tinyDelay = drand48() / 10
|
||||
UIView.animateWithDuration(0.5, delay: tinyDelay, usingSpringWithDamping: 0.9, initialSpringVelocity: 1.5, options: .BeginFromCurrentState, animations: { () -> Void in
|
||||
self.childA.frame = context.finalFrameForNode(self.childA)
|
||||
self.childB.frame = context.finalFrameForNode(self.childB)
|
||||
}, completion: {
|
||||
context.completeTransition($0)
|
||||
})
|
||||
}
|
||||
|
||||
enum State {
|
||||
case Right
|
||||
case Up
|
||||
case Left
|
||||
case Down
|
||||
|
||||
var isVertical: Bool {
|
||||
switch self {
|
||||
case .Up, .Down:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var isReverse: Bool {
|
||||
switch self {
|
||||
case .Left, .Up:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
mutating func advance() {
|
||||
switch self {
|
||||
case .Right:
|
||||
self = .Up
|
||||
case .Up:
|
||||
self = .Left
|
||||
case .Left:
|
||||
self = .Down
|
||||
case .Down:
|
||||
self = .Right
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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>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>CFBundleSignature</key>
|
||||
<string>????</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>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Utilities.swift
|
||||
// Texture
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
||||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIColor {
|
||||
static func random() -> UIColor {
|
||||
return UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// Texture
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
|
||||
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
|
||||
final class ViewController: ASViewController, ASCollectionDelegate, ASCollectionDataSource {
|
||||
let itemCount = 1000
|
||||
|
||||
let itemSize: CGSize
|
||||
let padding: CGFloat
|
||||
var collectionNode: ASCollectionNode {
|
||||
return node as! ASCollectionNode
|
||||
}
|
||||
|
||||
init() {
|
||||
let layout = UICollectionViewFlowLayout()
|
||||
(padding, itemSize) = ViewController.computeLayoutSizesForMainScreen()
|
||||
layout.minimumInteritemSpacing = padding
|
||||
layout.minimumLineSpacing = padding
|
||||
super.init(node: ASCollectionNode(collectionViewLayout: layout))
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Color", style: .Plain, target: self, action: #selector(didTapColorsButton))
|
||||
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Layout", style: .Plain, target: self, action: #selector(didTapLayoutButton))
|
||||
collectionNode.delegate = self
|
||||
collectionNode.dataSource = self
|
||||
title = "Background Updating"
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
// MARK: ASCollectionDataSource
|
||||
|
||||
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return itemCount
|
||||
}
|
||||
|
||||
func collectionView(collectionView: ASCollectionView, nodeBlockForItemAtIndexPath indexPath: NSIndexPath) -> ASCellNodeBlock {
|
||||
return {
|
||||
let node = DemoCellNode()
|
||||
node.backgroundColor = UIColor.random()
|
||||
node.childA.backgroundColor = UIColor.random()
|
||||
node.childB.backgroundColor = UIColor.random()
|
||||
return node
|
||||
}
|
||||
}
|
||||
|
||||
func collectionView(collectionView: ASCollectionView, constrainedSizeForNodeAtIndexPath indexPath: NSIndexPath) -> ASSizeRange {
|
||||
return ASSizeRangeMake(itemSize, itemSize)
|
||||
}
|
||||
|
||||
// MARK: Action Handling
|
||||
|
||||
@objc private func didTapColorsButton() {
|
||||
let currentlyVisibleNodes = collectionNode.view.visibleNodes()
|
||||
let queue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)
|
||||
dispatch_async(queue) {
|
||||
for case let node as DemoCellNode in currentlyVisibleNodes {
|
||||
node.backgroundColor = UIColor.random()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func didTapLayoutButton() {
|
||||
let currentlyVisibleNodes = collectionNode.view.visibleNodes()
|
||||
let queue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)
|
||||
dispatch_async(queue) {
|
||||
for case let node as DemoCellNode in currentlyVisibleNodes {
|
||||
node.state.advance()
|
||||
node.setNeedsLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Static
|
||||
|
||||
static func computeLayoutSizesForMainScreen() -> (padding: CGFloat, itemSize: CGSize) {
|
||||
let numberOfColumns = 4
|
||||
let screen = UIScreen.mainScreen()
|
||||
let scale = screen.scale
|
||||
let screenWidth = Int(screen.bounds.width * screen.scale)
|
||||
let itemWidthPx = (screenWidth - (numberOfColumns - 1)) / numberOfColumns
|
||||
let leftover = screenWidth - itemWidthPx * numberOfColumns
|
||||
let paddingPx = leftover / (numberOfColumns - 1)
|
||||
let itemDimension = CGFloat(itemWidthPx) / scale
|
||||
let padding = CGFloat(paddingPx) / scale
|
||||
return (padding: padding, itemSize: CGSize(width: itemDimension, height: itemDimension))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user