Skip to content

Commit 7c2d320

Browse files
authored
Merge pull request #24 from iWECon/dev
dev
2 parents 631933c + 7c3987c commit 7c2d320

17 files changed

+234
-624
lines changed

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
080677C628BE7D8B00000E16 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 080677C528BE7D8B00000E16 /* ViewController.swift */; };
1111
080677C828BE7DA400000E16 /* WrapStackDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 080677C728BE7DA400000E16 /* WrapStackDemoViewController.swift */; };
1212
08A24B8428E49A9600CDD7E2 /* LookinServer in Frameworks */ = {isa = PBXBuildFile; productRef = 08A24B8328E49A9600CDD7E2 /* LookinServer */; };
13-
08A24B8628E49C7A00CDD7E2 /* HVStackWrapperViewDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A24B8528E49C7A00CDD7E2 /* HVStackWrapperViewDemoViewController.swift */; };
1413
08E16CD9289ABA1C0019D7CB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08E16CD8289ABA1C0019D7CB /* AppDelegate.swift */; };
1514
08E16CDB289ABA1C0019D7CB /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08E16CDA289ABA1C0019D7CB /* SceneDelegate.swift */; };
1615
08E16CDD289ABA1C0019D7CB /* HVStackDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08E16CDC289ABA1C0019D7CB /* HVStackDemoViewController.swift */; };
@@ -24,7 +23,6 @@
2423
/* Begin PBXFileReference section */
2524
080677C528BE7D8B00000E16 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
2625
080677C728BE7DA400000E16 /* WrapStackDemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrapStackDemoViewController.swift; sourceTree = "<group>"; };
27-
08A24B8528E49C7A00CDD7E2 /* HVStackWrapperViewDemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HVStackWrapperViewDemoViewController.swift; sourceTree = "<group>"; };
2826
08E16CD5289ABA1C0019D7CB /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
2927
08E16CD8289ABA1C0019D7CB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3028
08E16CDA289ABA1C0019D7CB /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -75,7 +73,6 @@
7573
08E16CDA289ABA1C0019D7CB /* SceneDelegate.swift */,
7674
080677C528BE7D8B00000E16 /* ViewController.swift */,
7775
08E16CDC289ABA1C0019D7CB /* HVStackDemoViewController.swift */,
78-
08A24B8528E49C7A00CDD7E2 /* HVStackWrapperViewDemoViewController.swift */,
7976
080677C728BE7DA400000E16 /* WrapStackDemoViewController.swift */,
8077
08E16CDE289ABA1C0019D7CB /* Main.storyboard */,
8178
08E16CE1289ABA1D0019D7CB /* Assets.xcassets */,
@@ -183,7 +180,6 @@
183180
080677C628BE7D8B00000E16 /* ViewController.swift in Sources */,
184181
08E16CDD289ABA1C0019D7CB /* HVStackDemoViewController.swift in Sources */,
185182
080677C828BE7DA400000E16 /* WrapStackDemoViewController.swift in Sources */,
186-
08A24B8628E49C7A00CDD7E2 /* HVStackWrapperViewDemoViewController.swift in Sources */,
187183
08E16CD9289ABA1C0019D7CB /* AppDelegate.swift in Sources */,
188184
08E16CDB289ABA1C0019D7CB /* SceneDelegate.swift in Sources */,
189185
);

Demo/Demo/Base.lproj/Main.storyboard

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,18 @@
1818
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1919
<subviews>
2020
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="21" translatesAutoresizingMaskIntoConstraints="NO" id="M84-Lf-Gfo">
21-
<rect key="frame" x="87.5" y="375.5" width="239" height="145.5"/>
21+
<rect key="frame" x="135" y="403" width="144" height="90"/>
2222
<subviews>
2323
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="06f-Ws-ezl">
24-
<rect key="frame" x="0.0" y="0.0" width="239" height="34.5"/>
24+
<rect key="frame" x="0.0" y="0.0" width="144" height="34.5"/>
2525
<state key="normal" title="Button"/>
2626
<buttonConfiguration key="configuration" style="filled" title="H/VStackView"/>
2727
<connections>
2828
<segue destination="hGA-TO-DpM" kind="show" id="CVz-1t-QBY"/>
2929
</connections>
3030
</button>
31-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iYP-HX-gHv">
32-
<rect key="frame" x="0.0" y="55.5" width="239" height="34.5"/>
33-
<state key="normal" title="Button"/>
34-
<buttonConfiguration key="configuration" style="filled" title="H/VStackLayerWrapperView"/>
35-
<connections>
36-
<segue destination="5WQ-Nd-2jr" kind="show" id="Knm-qG-ruH"/>
37-
</connections>
38-
</button>
3931
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Dpb-UY-wFq">
40-
<rect key="frame" x="0.0" y="111" width="239" height="34.5"/>
32+
<rect key="frame" x="0.0" y="55.5" width="144" height="34.5"/>
4133
<state key="normal" title="Button"/>
4234
<buttonConfiguration key="configuration" style="filled" title="WrapStackView"/>
4335
<connections>
@@ -110,22 +102,6 @@
110102
</objects>
111103
<point key="canvasLocation" x="2077" y="555"/>
112104
</scene>
113-
<!--H/VStackLayerWrapperView-->
114-
<scene sceneID="9vs-48-r50">
115-
<objects>
116-
<viewController id="5WQ-Nd-2jr" customClass="HVStackWrapperViewDemoViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
117-
<view key="view" contentMode="scaleToFill" id="UXA-yy-xad">
118-
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
119-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
120-
<viewLayoutGuide key="safeArea" id="S0H-ab-HM3"/>
121-
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
122-
</view>
123-
<navigationItem key="navigationItem" title="H/VStackLayerWrapperView" id="lcg-7o-MOp"/>
124-
</viewController>
125-
<placeholder placeholderIdentifier="IBFirstResponder" id="eb2-QC-Y1T" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
126-
</objects>
127-
<point key="canvasLocation" x="2077" y="-790"/>
128-
</scene>
129105
</scenes>
130106
<resources>
131107
<systemColor name="systemBackgroundColor">

Demo/Demo/HVStackDemoViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class HVStackDemoViewController: UIViewController {
9090
}
9191

9292
HStackView(alignment: .top, distribution: .spacing(14), padding: UIEdgeInsets(top: 2, left: 12, bottom: 2, right: 6)) {
93-
VStackView {
93+
VStackView(padding: .init(top: 8, left: 0, bottom: 0, right: 0)) {
9494
UIView().stack.size(6).then {
9595
$0.backgroundColor = .systemBlue
9696
$0.layer.cornerRadius = 3

Demo/Demo/HVStackWrapperViewDemoViewController.swift

Lines changed: 0 additions & 175 deletions
This file was deleted.

Sources/StackKit/HStackView.swift

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ open class HStackView: UIView, StackView {
6767
}
6868
}
6969

70-
open var effectiveSubviews: [UIView] {
71-
subviews.filter { $0._isEffectiveView }
72-
}
73-
7470
public var contentSize: CGSize {
7571
let h = effectiveSubviews.map({ $0.frame }).reduce(CGRect.zero) { result, rect in
7672
result.union(rect)
@@ -91,11 +87,7 @@ open class HStackView: UIView, StackView {
9187
}
9288
}
9389

94-
open override func layoutSubviews() {
95-
super.layoutSubviews()
96-
97-
tryResizeStackView()
98-
90+
private func makeSubviewsAlignment() {
9991
switch alignment {
10092
case .top:
10193
effectiveSubviews.forEach { $0.frame.origin.y = _stackContentRect.minY }
@@ -104,6 +96,14 @@ open class HStackView: UIView, StackView {
10496
case .bottom:
10597
effectiveSubviews.forEach { $0.frame.origin.y = _stackContentRect.maxY - $0.frame.height }
10698
}
99+
}
100+
101+
open override func layoutSubviews() {
102+
super.layoutSubviews()
103+
104+
tryResizeStackView()
105+
106+
makeSubviewsAlignment()
107107

108108
switch distribution {
109109
case .spacing(let spacing):
@@ -180,7 +180,7 @@ extension HStackView {
180180
private func makeSpacing(_ spacing: CGFloat) {
181181
for (index, subview) in effectiveSubviews.enumerated() {
182182
if index == 0 {
183-
subview.frame.origin.x = _stackContentRect.minX
183+
subview.frame.origin.x = paddingLeft
184184
} else {
185185
let previousView = effectiveSubviews[index - 1]
186186
if (previousView as? SpacerView) != nil || (subview as? SpacerView) != nil { // spacer and view no spacing
@@ -197,19 +197,18 @@ extension HStackView {
197197
frame.size.height = contentSize.height
198198
}
199199
for subview in effectiveSubviews {
200-
let oldHeight = subview.frame.height
201200
subview.frame.size.height = _stackContentWidth
202201

203202
// fix #https://github.com/iWECon/StackKit/issues/21
204203
guard alignment == .center else {
205204
continue
206205
}
207-
subview.frame.origin.y -= (_stackContentWidth - oldHeight) / 2
206+
subview.center.y = _stackContentRect.midY
208207
}
209208
}
210209

211210
private func fillWidth() {
212-
let maxW = frame.width - lengthOfAllFixedLengthSpacer() - dividerSpecifyLength()
211+
let maxW = frame.width - lengthOfAllFixedLengthSpacer() - lengthOfAllFixedLengthDivider()
213212
var w = (maxW) / CGFloat(viewsWithoutSpacerAndDivider().count)
214213

215214
let unspacersView = viewsWithoutSpacerAndDivider()
@@ -223,12 +222,6 @@ extension HStackView {
223222
// MARK: Divider
224223
extension HStackView {
225224

226-
private func dividerSpecifyLength() -> CGFloat {
227-
dividerViews()
228-
.map({ $0.thickness })
229-
.reduce(0, +)
230-
}
231-
232225
private func fillDivider() {
233226
let maxHeight = effectiveSubviews.filter({ ($0 as? DividerView) == nil }).map({ $0.frame.size.height }).max() ?? frame.height
234227
for divider in effectiveSubviews.compactMap({ $0 as? DividerView }) {
@@ -291,7 +284,7 @@ extension HStackView {
291284

292285
// 非 spacerView 的所有宽度
293286
let unspacerViewsMaxWidth = unspacerViewsWidth + unspacerViewsSpacing
294-
let spacersWidth = (frame.width - unspacerViewsMaxWidth - self.lengthOfAllFixedLengthSpacer())
287+
let spacersWidth = (_stackContentWidth - unspacerViewsMaxWidth - self.lengthOfAllFixedLengthSpacer())
295288
let spacerWidth = spacersWidth / CGFloat(self.dynamicSpacerViews().count)
296289

297290
let spacerViews = self.spacerViews()

0 commit comments

Comments
 (0)