Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully support NS/UILayoutGuide and SwiftPM #594

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
---
language: objective-c
osx_image: xcode9
osx_image: xcode12
before_install:
- sudo easy_install cpp-coveralls
- curl -L https://bootstrap.pypa.io/pip/2.7/get-pip.py | sudo python
- sudo pip install cpp-coveralls
- gem install xcpretty -N
- export LANG=en_US.UTF-8

script:
- set -o pipefail
- xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry iOS Tests' -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.0' clean test ARCHS=i386 VALID_ARCHS=i386 ONLY_ACTIVE_ARCH=NO GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES | xcpretty -c
- xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry iOS' -configuration Debug -sdk iphonesimulator clean build ARCHS=i386 VALID_ARCHS=i386 ONLY_ACTIVE_ARCH=NO | xcpretty -c
- xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry OSX' -configuration Debug clean build | xcpretty -c
- xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry iOS Tests' -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8,OS=14.0' clean test ARCHS=x86_64 VALID_ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES | xcpretty -c
- xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry' -configuration Debug -sdk iphonesimulator clean build ARCHS=x86_64 VALID_ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO | xcpretty -c
- xcodebuild -workspace 'Masonry.xcworkspace' -scheme 'Masonry' -configuration Debug -sdk macosx clean build | xcpretty -c

after_success:
- ./script/coveralls.sh
10 changes: 5 additions & 5 deletions Masonry.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = 'Masonry'
s.version = '1.1.0'
s.version = '1.2.0'
s.license = 'MIT'
s.summary = 'Harness the power of Auto Layout NSLayoutConstraints with a simplified, chainable and expressive syntax.'
s.homepage = 'https://github.com/cloudkite/Masonry'
s.homepage = 'https://github.com/SnapKit/Masonry'
s.author = { 'Jonas Budelmann' => '[email protected]' }
s.social_media_url = "http://twitter.com/cloudkite"

s.source = { :git => 'https://github.com/cloudkite/Masonry.git', :tag => "v#{s.version}" }
s.source = { :git => 'https://github.com/SnapKit/Masonry.git', :tag => "v#{s.version}" }

s.description = %{
Masonry is a light-weight layout framework which wraps AutoLayout with a nicer syntax.
Expand All @@ -31,8 +31,8 @@ Pod::Spec.new do |s|
s.tvos.frameworks = 'Foundation', 'UIKit'
s.osx.frameworks = 'Foundation', 'AppKit'

s.ios.deployment_target = '6.0' # minimum SDK with autolayout
s.osx.deployment_target = '10.7' # minimum SDK with autolayout
s.ios.deployment_target = '9.0' # minimum SDK with autolayout
s.osx.deployment_target = '10.11' # minimum SDK with autolayout
s.tvos.deployment_target = '9.0' # minimum SDK with autolayout
s.requires_arc = true
end
205 changes: 51 additions & 154 deletions Masonry.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

82 changes: 0 additions & 82 deletions Masonry.xcodeproj/xcshareddata/xcschemes/Masonry OSX.xcscheme

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -16,7 +16,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "3AED05B61AD59FD40053CC65"
BuildableName = "Masonry.framework"
BlueprintName = "Masonry iOS"
BlueprintName = "Masonry"
ReferencedContainer = "container:Masonry.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -26,35 +26,20 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3AED05B61AD59FD40053CC65"
BuildableName = "Masonry.framework"
BlueprintName = "Masonry iOS"
ReferencedContainer = "container:Masonry.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -67,7 +52,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "3AED05B61AD59FD40053CC65"
BuildableName = "Masonry.framework"
BlueprintName = "Masonry iOS"
BlueprintName = "Masonry"
ReferencedContainer = "container:Masonry.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand Down
65 changes: 65 additions & 0 deletions Masonry/LayoutGuide+MASAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// LayoutGuide+MASAdditions.h
// Masonry
//
// Created by v on 2021/5/30.
// Copyright © 2021 Jonas Budelmann. All rights reserved.
//

#import "MASUtilities.h"
#import "MASConstraintMaker.h"
#import "MASViewAttribute.h"

NS_ASSUME_NONNULL_BEGIN

API_AVAILABLE(macos(10.11), ios(9.0))
@interface MASLayoutGuide (MASAdditions)

@property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_leading;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_width;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_height;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;

@property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr);

/**
* Creates a MASConstraintMaker with the callee view.
* Any constraints defined are added to the view or the appropriate superview once the block has finished executing
*
* @param block scope within which you can build up the constraints which you wish to apply to the view.
*
* @return Array of created MASConstraints
*/
- (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(id<MASLayoutConstraint> make))block;

/**
* Creates a MASConstraintMaker with the callee view.
* Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
* If an existing constraint exists then it will be updated instead.
*
* @param block scope within which you can build up the constraints which you wish to apply to the view.
*
* @return Array of created/updated MASConstraints
*/
- (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(id<MASLayoutConstraint> make))block;

/**
* Creates a MASConstraintMaker with the callee view.
* Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
* All constraints previously installed for the view will be removed.
*
* @param block scope within which you can build up the constraints which you wish to apply to the view.
*
* @return Array of created/updated MASConstraints
*/
- (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(id<MASLayoutConstraint> make))block;

@end

NS_ASSUME_NONNULL_END
83 changes: 83 additions & 0 deletions Masonry/LayoutGuide+MASAdditions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// LayoutGuide+MASAdditions.m
// Masonry
//
// Created by v on 2021/5/30.
// Copyright © 2021 Jonas Budelmann. All rights reserved.
//

#import "LayoutGuide+MASAdditions.h"
#import <objc/runtime.h>


@implementation MASLayoutGuide (MASAdditions)

- (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(id<MASLayoutConstraint> make))block {
MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithLayoutGuide:self];
block(constraintMaker);
return [constraintMaker install];
}

- (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(id<MASLayoutConstraint> make))block {
MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithLayoutGuide:self];
constraintMaker.updateExisting = YES;
block(constraintMaker);
return [constraintMaker install];
}

- (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(id<MASLayoutConstraint> make))block {
MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithLayoutGuide:self];
constraintMaker.removeExisting = YES;
block(constraintMaker);
return [constraintMaker install];
}

#pragma mark - NSLayoutAttribute properties

- (MASViewAttribute *)mas_left {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeLeft];
}

- (MASViewAttribute *)mas_top {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeTop];
}

- (MASViewAttribute *)mas_right {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeRight];
}

- (MASViewAttribute *)mas_bottom {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeBottom];
}

- (MASViewAttribute *)mas_leading {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeLeading];
}

- (MASViewAttribute *)mas_trailing {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeTrailing];
}

- (MASViewAttribute *)mas_width {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeWidth];
}

- (MASViewAttribute *)mas_height {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeHeight];
}

- (MASViewAttribute *)mas_centerX {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeCenterX];
}

- (MASViewAttribute *)mas_centerY {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:NSLayoutAttributeCenterY];
}

- (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute {
return ^(NSLayoutAttribute attr) {
return [[MASViewAttribute alloc] initWithView:self.owningView item:self layoutAttribute:attr];
};
}

@end
43 changes: 43 additions & 0 deletions Masonry/LayoutGuide+MASShorthandAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// LayoutGuide+MASShorthandAdditions.h
// Masonry
//
// Created by v on 2021/6/1.
// Copyright © 2021 Jonas Budelmann. All rights reserved.
//

#import "LayoutGuide+MASAdditions.h"

NS_ASSUME_NONNULL_BEGIN

#ifdef MAS_SHORTHAND

/**
* Shorthand view additions without the 'mas_' prefixes,
* only enabled if MAS_SHORTHAND is defined
*/
API_AVAILABLE(macos(10.11), ios(9.0))
@interface MASLayoutGuide (MASShorthandAdditions)

@property (nonatomic, strong, readonly) MASViewAttribute *left;
@property (nonatomic, strong, readonly) MASViewAttribute *top;
@property (nonatomic, strong, readonly) MASViewAttribute *right;
@property (nonatomic, strong, readonly) MASViewAttribute *bottom;
@property (nonatomic, strong, readonly) MASViewAttribute *leading;
@property (nonatomic, strong, readonly) MASViewAttribute *trailing;
@property (nonatomic, strong, readonly) MASViewAttribute *width;
@property (nonatomic, strong, readonly) MASViewAttribute *height;
@property (nonatomic, strong, readonly) MASViewAttribute *centerX;
@property (nonatomic, strong, readonly) MASViewAttribute *centerY;

@property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr);

- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;

@end

#endif

NS_ASSUME_NONNULL_END
Loading