Skip to content

Commit 9c15fc0

Browse files
committed
Fix hwrap/vwrap on macos
1 parent 8548f65 commit 9c15fc0

File tree

8 files changed

+24
-30
lines changed

8 files changed

+24
-30
lines changed

Sources/CALayer+LX.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ private var key: UInt8 = 0
1414
private var viewPortInsetsKey: UInt8 = 0
1515

1616
extension CALayer: Layoutable {
17-
public var lx_bounds: CGRect {
18-
return bounds
19-
}
2017

2118
public var lx_frame: CGRect {
2219
get {
2320
#if os(macOS)
24-
return frame.flipped(in: superlayer?.bounds ?? bounds)
21+
return frame.flipped(in: superlayer?.bounds)
2522
#else
2623
return frame
2724
#endif
2825
}
2926
set {
3027
#if os(macOS)
31-
frame = newValue.flipped(in: superlayer?.bounds ?? bounds)
28+
frame = newValue.flipped(in: superlayer?.bounds)
3229
#else
3330
frame = newValue
3431
#endif

Sources/LX.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import UIKit
1313

1414
public protocol Layoutable: class {
1515
var lx_parent: Layoutable? {get}
16-
var lx_bounds: CGRect {get}
1716
var lx_frame: CGRect {get set}
1817
var lx_viewport: CGRect? {get set}
1918
func lx_sizeThatFits(_ size: CGSize) -> CGSize
2019
}
2120

2221
extension Layoutable {
22+
23+
public var lx_bounds: CGRect {
24+
return CGRect(x: 0, y: 0, width: lx_frame.width, height: lx_frame.height)
25+
}
26+
2327
func updateFrame(_ newValue: CGRect) {
2428
lx_frame = CGRect(x: newValue.origin.x.pixelPerfect, y: newValue.origin.y.pixelPerfect, width: newValue.size.width.ceilPixelPerfect, height: newValue.size.height.ceilPixelPerfect)
2529
}

Sources/Node.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ public protocol NodeContainer: Layoutable {
4141
open class Node<T: NodeContainer>: NodeProtocol {
4242

4343
//MARK: - confirm layoutable
44-
public var lx_bounds: CGRect {
45-
return bounds
46-
}
4744

4845
public var lx_frame: CGRect {
4946
get {

Sources/PutWrap.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,25 @@ private func putOperation<T: BoxDimension>(_ superview: Layoutable, intentions:
248248

249249
var totalSizeForFlexs = T.getDimension(bounds).size
250250

251+
252+
var totalFix: CGFloat = 0.0
253+
251254
for i in intentions {
252255
switch (i) {
253256
case .flex(_, let weight):
254257
totalWeight += weight
255258
case .fix(let views, let value):
256-
totalSizeForFlexs -= value.calculateValue(forViews: views, dimension: dimension)
259+
let v = value.calculateValue(forViews: views, dimension: dimension)
260+
totalFix += v
261+
totalSizeForFlexs -= v
257262
}
258263
}
259264

265+
if wrapParent {
266+
let dim = T.getDimension(superview.lx_frame)
267+
superview.lx_frame = T.setDimension(Dimension(origin: dim.origin, size: totalFix - dim.origin), inRect: superview.lx_frame)
268+
}
269+
260270
let unoSize = totalSizeForFlexs/totalWeight
261271

262272
var start = T.getDimension(bounds).origin
@@ -267,7 +277,7 @@ private func putOperation<T: BoxDimension>(_ superview: Layoutable, intentions:
267277
let newSize = weight * unoSize
268278

269279
if let views = views {
270-
views.forEach {view in
280+
views.forEach { view in
271281
let fr = view.lx_frame
272282
view.updateFrame(T.setDimension(Dimension(origin: start, size: newSize), inRect: fr))
273283
}
@@ -289,10 +299,7 @@ private func putOperation<T: BoxDimension>(_ superview: Layoutable, intentions:
289299
}
290300
}
291301

292-
if wrapParent {
293-
let dim = T.getDimension(superview.lx_frame)
294-
superview.lx_frame = T.setDimension(Dimension(origin: dim.origin, size: start - T.getDimension(bounds).origin), inRect: superview.lx_frame)
295-
}
302+
296303
}
297304

298305
extension Layouting where Base: Layoutable {

Sources/RootNode.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import Foundation
1313
public final class RootNode: Layoutable {
1414

1515
//MARK: - confirm layoutable
16-
public var lx_bounds: CGRect {
17-
return bounds
18-
}
1916

2017
public var lx_frame: CGRect {
2118
get {

Sources/UIKit/NSView+LX.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,19 @@ extension NSView: Layoutable {
1717
return superview
1818
}
1919

20-
public var lx_bounds: CGRect {
21-
return bounds
22-
}
23-
2420
public var lx_frame: CGRect {
2521
get {
2622
if superview?.isFlipped ?? false {
2723
return frame
2824
} else {
29-
return frame.flipped(in: superview?.bounds ?? bounds)
25+
return frame.flipped(in: superview?.bounds)
3026
}
3127
}
3228
set {
3329
if superview?.isFlipped ?? false {
3430
frame = newValue
3531
} else {
36-
frame = newValue.flipped(in: superview?.bounds ?? bounds)
32+
frame = newValue.flipped(in: superview?.bounds)
3733
}
3834

3935
}

Sources/UIKit/UIView+LX.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ private var viewPortInsetsKey: UInt8 = 0
1414

1515
extension UIView: Layoutable {
1616

17-
public var lx_bounds: CGRect {
18-
return bounds
19-
}
20-
2117
public var lx_frame: CGRect {
2218
get {
2319
return frame

Sources/Utils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension CGFloat {
3232

3333
extension CGRect {
3434
//convert from cartesian <-> flipped coordinate space
35-
func flipped(in rect: CGRect) -> CGRect {
36-
return CGRect(x: minX, y: rect.height - maxY, width: width, height: height)
35+
func flipped(in rect: CGRect?) -> CGRect {
36+
return CGRect(x: minX, y: (rect?.height ?? 0) - maxY, width: width, height: height)
3737
}
3838
}

0 commit comments

Comments
 (0)