Skip to content

Instantly share code, notes, and snippets.

View GeekTree0101's full-sized avatar
πŸš€

David Ha (小河) GeekTree0101

πŸš€
View GitHub Profile
@GeekTree0101
GeekTree0101 / Mergeable.swift
Created May 13, 2018 12:39
Mergeable Protocol Example
import Foundation
protocol Mergeable {
func merge(_ target: Self)
}
extension Mergeable {
func merge(_ target: Self) {
guard let source = self as? NSObject else { return }
@GeekTree0101
GeekTree0101 / UserTest.swift
Created May 13, 2018 12:42
Test Mergeable Protocol
class User: NSObject, Decodable, Mergeable {
@objc var username: String = ""
@objc var profileURL: URL?
enum CodingKeys: String, CodingKey {
case username = "login"
case profileURL = "avatar_url"
}
}
@GeekTree0101
GeekTree0101 / ASBidirectionFetchExample.swift
Created June 6, 2018 02:54
ASBatchFetching Customize for Bidirectional Fetching
import Foundation
import AsyncDisplayKit
public protocol ChatNodeDelegate: ASCollectionDelegate {
func shouldAppendBatchFetch(for chatNode: ASCollectionNode) -> Bool
func shouldPrependBatchFetch(for chatNode: ASCollectionNode) -> Bool
func chatNode(_ chatNode: ASCollectionNode,
willBeginAppendBatchFetchWith context: ASBatchContext)
@GeekTree0101
GeekTree0101 / ChatFlowLayoutExample.swift
Created June 6, 2018 03:14
Texture Chat Application UICollectionView Flow Layout Example
import Foundation
import AsyncDisplayKit
class ChatFlowLayoutExample: UICollectionViewFlowLayout {
private var topVisibleItem = Int.max
private var bottomVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?
private var isPrepend: Bool = false
@GeekTree0101
GeekTree0101 / Texture-GradientLayout.swift
Created July 18, 2018 14:03
Texture GradientLayout Example
class mothorNode: ASDisplayNode {
let childNode = ASDisplayNode()
// ....omit.....
override func layoutDidFinish() {
super.layoutDidFinish()
self.childNode
.gradientBackgroundColor([UIColor.red.cgColor, UIColor.white.cgColor],
direction: .horizontal)
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let contentLayout = contentLayoutSpec()
contentLayout.style.flexShrink = 1.0
contentLayout.style.flexGrow = 1.0
userProfileNode.style.flexShrink = 1.0
userProfileNode.style.flexGrow = 0.0
let stackLayout = ASStackLayoutSpec(direction: .horizontal,
spacing: 10.0,
@GeekTree0101
GeekTree0101 / FrameDropExampleVideoFeed.swift
Last active July 22, 2018 14:43
Simple Video Feed Frame Drop Example
import AsyncDisplayKit
class VideoFeedController: ASViewController<ASTableNode>, ASTableDataSource {
required init() {
super.init(node: ASTableNode.init(style: .plain))
self.node.dataSource = self
}
required init?(coder aDecoder: NSCoder) {
@GeekTree0101
GeekTree0101 / ASVideoNode-Feed-Example.swift
Last active January 13, 2021 03:01
Simple Video Feed Performance Improvement Experiment
import AsyncDisplayKit
struct VideoProcessing {
private static let loadOperation: OperationQueue = {
let operationQueue = OperationQueue()
operationQueue.maxConcurrentOperationCount = 3
operationQueue.name = "com.VideoFeedController.VideoLoaderOperation"
operationQueue.qualityOfService = .utility
return operationQueue
}()
@GeekTree0101
GeekTree0101 / ModelSyncronizer.swift
Last active August 7, 2018 08:51
ModelSyncronizer Best Practice
import RxCocoa
import RxSwift
import Foundation
// Model Syncronizer
struct UserSyncronizer {
static private let syncronizer = PublishRelay<User?>()
static func observable(_ id: Int) -> Observable<User?> {
// subscribe on background('default') scheduler
@GeekTree0101
GeekTree0101 / ASDisplayNode+Gradient.swift
Created September 16, 2018 04:06
CAGradientLayer with Texture Example
import AsyncDisplayKit
extension ASDisplayNode {
enum GradientDirection {
case horizontal
case vertical
case adjust(CGPoint, CGPoint)
var points: (start: CGPoint, end: CGPoint) {
switch self {