Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
the layout function will make the code-completion invalid
  • Loading branch information
protosse committed May 14, 2021
commit 80d7fd10860187e69b8f93ba7d68caa90c849be1
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,26 @@ - (void) layoutSubviews {
// [[[[segmented.pinObjc rightOf:logo aligned:VerticalAlignTop] rightWithInsets:safeArea] marginHorizontal:margin] layout];
// [[[[[[textLabel.pinObjc belowOf:segmented aligned:HorizontalAlignLeft] widthOf:segmented] pinEdges] marginTop:margin] sizeToFit:FitWidth] layout];
// [[[[[separatorView.pinObjc belowOfViews:@[logo, textLabel] aligned:HorizontalAlignLeft] rightTo:segmented.edge.right] height:1] marginTop:margin] layout];
[logo.pinObjc
logo.pinObjc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put this on a single line, so that it matches Swift style?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK👌

.topInsets(safeArea)
.leftInsets(safeArea)
.width(100).aspectRatio()
.margin(margin) layout];
[segmented.pinObjc
.margin(margin).layout();
segmented.pinObjc
.rightOfAligned(logo, VerticalAlignTop)
.rightInsets(safeArea)
.marginHorizontal(margin) layout];
[textLabel.pinObjc
.marginHorizontal(margin).layout();
textLabel.pinObjc
.belowOfAligned(segmented, HorizontalAlignLeft)
.widthOf(segmented)
.pinEdges()
.marginTop(margin)
.sizeToFitType(FitWidth) layout];
[separatorView.pinObjc
.sizeToFitType(FitWidth).layout();
separatorView.pinObjc
.belowOfViewsAligned(@[logo, textLabel], HorizontalAlignLeft)
.rightToEdge(segmented.edge.right)
.height(1)
.marginTop(margin) layout];
.marginTop(margin).layout();
}

- (void) setLayoutGuidesTop:(CGFloat)top {
Expand Down
17 changes: 8 additions & 9 deletions Sources/ObjectiveC/PinLayoutObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ import AppKit
#if os(iOS) || os(tvOS)
var safeArea: PEdgeInsets { get }
#endif

/**
With the Objective-C interface, you must call the \"layout\" method to ensure the view is layouted correctly.
Ex:
[[[textLabel.pin_objc top] left] layout];"
[[[textLabel.pin_objc top] left] layout];"
*/
func layout()


typealias POVoid = () -> PinLayoutObjC?
typealias POValue = (_ value: CGFloat) -> PinLayoutObjC?
typealias POEdgeInsets = (_ insets: PEdgeInsets) -> PinLayoutObjC?
Expand All @@ -56,6 +48,13 @@ import AppKit
typealias POWrapTypeInsets = (_ type: WrapType, _ insets: PEdgeInsets) -> PinLayoutObjC?
typealias POFitType = (_ type: Fit) -> PinLayoutObjC?

/**
With the Objective-C interface, you must call the \"layout\" method to ensure the view is layouted correctly.
Ex:
textLabel.pinObjc.top().left().layout()
*/
var layout: POVoid { get }

var top: POVoid { get }
var topValue: POValue { get }
var topPercent: POValue { get }
Expand Down
11 changes: 6 additions & 5 deletions Sources/ObjectiveC/PinLayoutObjCImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ import AppKit
}
}

func layout() {
// With objective-c PinLayoutObjCImpl instance are sometimes deallocated only after the context has been quit. For this reason
// developpers must call the layout: method implicetely.
impl?.layout()
impl = nil
var layout: POVoid {
return { [weak self] in
_ = self?.impl?.layout()
self?.impl = nil
return self
}
}

var top: POVoid {
Expand Down