forked from LinkedInAttic/LayoutKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDividerStackLayout.swift
More file actions
42 lines (38 loc) · 1.7 KB
/
DividerStackLayout.swift
File metadata and controls
42 lines (38 loc) · 1.7 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
// Copyright 2016 LinkedIn Corp.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import UIKit
import LayoutKit
/**
A layout that places a divider view in the spacing between the stack's sublayouts.
*/
open class DividerStackLayout<DividerView: View, V: View>: StackLayout<V> {
public init(stack: StackLayout<V>, dividerConfig: ((DividerView) -> Void)?) {
let sublayouts: [Layout]
if stack.spacing > 0 {
var dividedSublayouts = [Layout]()
let size = AxisSize(axis: stack.axis, axisLength: stack.spacing, crossLength: 0).size
let divider = SizeLayout<DividerView>(size: size, alignment: .fill, flexibility: .flexible, config: dividerConfig)
for (index, sublayout) in stack.sublayouts.enumerated() {
dividedSublayouts.append(sublayout)
if index != stack.sublayouts.count - 1 {
dividedSublayouts.append(divider)
}
}
sublayouts = dividedSublayouts
} else {
sublayouts = stack.sublayouts
}
super.init(axis: stack.axis,
spacing: 0,
distribution: stack.distribution,
alignment: stack.alignment,
flexibility: stack.flexibility,
sublayouts: sublayouts,
config: stack.config)
}
}