-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathVisibleFrameInsetLayout.swift
More file actions
36 lines (30 loc) · 980 Bytes
/
VisibleFrameInsetLayout.swift
File metadata and controls
36 lines (30 loc) · 980 Bytes
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
//
// VisibleFrameInsetLayout.swift
// CollectionKit
//
// Created by Luke Zhao on 2018-03-23.
// Copyright © 2018 lkzhao. All rights reserved.
//
import UIKit
open class VisibleFrameInsetLayout: WrapperLayout {
public var insets: UIEdgeInsets
public var insetProvider: ((CGSize) -> UIEdgeInsets)?
public init(_ rootLayout: Layout, insets: UIEdgeInsets = .zero) {
self.insets = insets
super.init(rootLayout)
}
public init(_ rootLayout: Layout, insetProvider: @escaping ((CGSize) -> UIEdgeInsets)) {
self.insets = .zero
self.insetProvider = insetProvider
super.init(rootLayout)
}
open override func layout(context: LayoutContext) {
if let insetProvider = insetProvider {
insets = insetProvider(context.collectionSize)
}
super.layout(context: context)
}
open override func visible(in visibleFrame: CGRect) -> (indexes: [Int], frame: CGRect) {
return rootLayout.visible(in: visibleFrame.inset(by: insets))
}
}