-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathTransposeLayout.swift
More file actions
48 lines (41 loc) · 1.28 KB
/
TransposeLayout.swift
File metadata and controls
48 lines (41 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// TransposeLayout.swift
// CollectionKit
//
// Created by Luke Zhao on 2017-09-08.
// Copyright © 2017 lkzhao. All rights reserved.
//
import UIKit
open class TransposeLayout: WrapperLayout {
struct TransposeLayoutContext: LayoutContext {
var original: LayoutContext
var collectionSize: CGSize {
return original.collectionSize.transposed
}
var numberOfItems: Int {
return original.numberOfItems
}
func data(at: Int) -> Any {
return original.data(at: at)
}
func identifier(at: Int) -> String {
return original.identifier(at: at)
}
func size(at: Int, collectionSize: CGSize) -> CGSize {
return original.size(at: at, collectionSize: collectionSize.transposed).transposed
}
}
open override var contentSize: CGSize {
return rootLayout.contentSize.transposed
}
open override func layout(context: LayoutContext) {
rootLayout.layout(context: TransposeLayoutContext(original: context))
}
open override func visible(in visibleFrame: CGRect) -> (indexes: [Int], frame: CGRect) {
let visible = rootLayout.visible(in: visibleFrame.transposed)
return (visible.indexes, visible.frame.transposed)
}
open override func frame(at: Int) -> CGRect {
return rootLayout.frame(at: at).transposed
}
}