Skip to content

Commit d0f888a

Browse files
committed
offset Support
1 parent 3399b55 commit d0f888a

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

Sources/StackKit/HStackView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ extension HStackView {
172172
subview.frame.origin.x = previousView.frame.maxX + spacing
173173
}
174174
}
175+
176+
guard let offset = subview._stackKit_offset else {
177+
continue
178+
}
179+
subview.frame.origin.x += offset.x
180+
subview.frame.origin.y += offset.y
175181
}
176182
}
177183

Sources/StackKit/UIView+StackKit/UIView+StackKitCompatibleProvider.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ extension UIView: StackKitCompatibleProvider { }
1313

1414
extension StackKitCompatible where Base: UIView {
1515

16+
@discardableResult
17+
public func offset(_ value: CGPoint?) -> Self {
18+
view._stackKit_offset = value
19+
return self
20+
}
21+
1622
@discardableResult
1723
public func width(_ value: CGFloat?) -> Self {
1824
view._stackKit_width = value

Sources/StackKit/UIView+StackKit/_UIView_StackKitProvider.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import UIKit
22

33
struct _UIView_StackKitKeys {
4+
static var offsetKey = "StackKit_offsetKey"
5+
46
static var widthKey = "StackKit_widthKey"
57
static var heightKey = "StackKit_heightKey"
68

@@ -12,6 +14,8 @@ struct _UIView_StackKitKeys {
1214
}
1315

1416
protocol _UIView_StackKitProvider {
17+
var _stackKit_offset: CGPoint? { get set }
18+
1519
var _stackKit_width: CGFloat? { get set }
1620
var _stackKit_height: CGFloat? { get set }
1721

@@ -24,6 +28,22 @@ protocol _UIView_StackKitProvider {
2428

2529
extension UIView: _UIView_StackKitProvider {
2630

31+
var _stackKit_offset: CGPoint? {
32+
get {
33+
guard let value = Runtime.getProperty(self, key: &_UIView_StackKitKeys.offsetKey) as? NSValue else {
34+
return nil
35+
}
36+
return value.cgPointValue
37+
}
38+
set {
39+
guard let newValue else {
40+
Runtime.setProperty(self, key: &_UIView_StackKitKeys.offsetKey, value: nil, policy: .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
41+
return
42+
}
43+
Runtime.setProperty(self, key: &_UIView_StackKitKeys.offsetKey, value: NSValue(cgPoint: newValue), policy: .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
44+
}
45+
}
46+
2747
var _stackKit_width: CGFloat? {
2848
get {
2949
Runtime.getCGFloatProperty(self, key: &_UIView_StackKitKeys.widthKey)

Sources/StackKit/VStackView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ extension VStackView {
164164
subview.frame.origin.y = previousView.frame.maxY + spacing
165165
}
166166
}
167+
168+
guard let offset = subview._stackKit_offset else {
169+
continue
170+
}
171+
subview.frame.origin.x += offset.x
172+
subview.frame.origin.y += offset.y
167173
}
168174
}
169175

0 commit comments

Comments
 (0)