Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ios
/
Masonry
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
Jonas Budelmann
12 years ago
Commit
c52bb5a2163d1358bbd8c78baf6c3e64bfd2e32a
1 parent
f948d2e8
remove unused completedChildConstraints array
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
63 deletions
Masonry/MASCompositeConstraint.m
MasonryTests/MASCompositeConstraintSpec.m
Masonry/MASCompositeConstraint.m
View file @
c52bb5a
...
...
@@ -12,8 +12,7 @@
@interface
MASCompositeConstraint
()
<
MASConstraintDelegate
>
@property
(
nonatomic
,
strong
)
NSMutableArray
*
completedChildConstraints
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
currentChildConstraints
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
childConstraints
;
@property
(
nonatomic
,
assign
)
BOOL
added
;
@end
...
...
@@ -27,14 +26,13 @@
_view
=
view
;
_type
=
type
;
self
.
completedChildConstraints
=
NSMutableArray
.
array
;
[
self
createChildren
];
return
self
;
}
-
(
void
)
createChildren
{
self
.
c
urrentC
hildConstraints
=
NSMutableArray
.
array
;
self
.
childConstraints
=
NSMutableArray
.
array
;
NSArray
*
viewAttributes
;
switch
(
self
.
type
)
{
...
...
@@ -59,21 +57,21 @@
for
(
MASViewAttribute
*
viewAttribute
in
viewAttributes
)
{
MASViewConstraint
*
child
=
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
viewAttribute
];
child
.
delegate
=
self
;
[
self
.
c
urrentC
hildConstraints
addObject
:
child
];
[
self
.
childConstraints
addObject
:
child
];
}
}
#pragma mark - MASConstraintDelegate
-
(
void
)
addConstraint
:
(
id
<
MASConstraint
>
)
constraint
{
[
self
.
completedChildConstraints
addObjec
t
:
constraint
];
[
self
.
delegate
addConstrain
t
:
constraint
];
}
#pragma mark - NSLayoutConstraint constant proxies
-
(
id
<
MASConstraint
>
(
^
)(
UIEdgeInsets
))
insets
{
return
^
id
(
UIEdgeInsets
insets
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
c
urrentC
hildConstraints
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
insets
(
insets
);
}
return
self
;
...
...
@@ -82,7 +80,7 @@
-
(
id
<
MASConstraint
>
(
^
)(
CGFloat
))
offset
{
return
^
id
(
CGFloat
offset
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
c
urrentC
hildConstraints
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
offset
(
offset
);
}
return
self
;
...
...
@@ -91,7 +89,7 @@
-
(
id
<
MASConstraint
>
(
^
)(
CGSize
))
sizeOffset
{
return
^
id
(
CGSize
offset
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
c
urrentC
hildConstraints
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
sizeOffset
(
offset
);
}
return
self
;
...
...
@@ -100,7 +98,7 @@
-
(
id
<
MASConstraint
>
(
^
)(
CGPoint
))
centerOffset
{
return
^
id
(
CGPoint
offset
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
c
urrentC
hildConstraints
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
centerOffset
(
offset
);
}
return
self
;
...
...
@@ -111,7 +109,7 @@
-
(
id
<
MASConstraint
>
(
^
)(
CGFloat
))
percent
{
return
^
id
(
CGFloat
percent
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
c
urrentC
hildConstraints
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
percent
(
percent
);
}
return
self
;
...
...
@@ -122,7 +120,7 @@
-
(
id
<
MASConstraint
>
(
^
)(
MASLayoutPriority
))
priority
{
return
^
id
(
MASLayoutPriority
priority
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
c
urrentC
hildConstraints
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
priority
(
priority
);
}
return
self
;
...
...
@@ -152,35 +150,31 @@
#pragma mark - NSLayoutRelation proxies
-
(
id
<
MASConstraint
>
(
^
)(
id
))
relationWithBlock
:
(
id
<
MASConstraint
>
(
^
)(
id
<
MASConstraint
>
constraint
,
id
attr
))
block
{
-
(
id
<
MASConstraint
>
(
^
)(
id
))
equalTo
{
return
^
id
(
id
attr
)
{
if
(
!
self
.
added
)
{
[
self
.
delegate
addConstraint
:
self
];
self
.
added
=
YES
;
}
for
(
id
<
MASConstraint
>
constraint
in
self
.
currentChildConstraints
)
{
block
(
constraint
,
attr
);
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
equalTo
(
attr
);
}
return
self
;
};
}
-
(
id
<
MASConstraint
>
(
^
)(
id
))
equalTo
{
return
[
self
relationWithBlock
:
^
id
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
constraint
.
equalTo
(
attr
)
;
}];
}
-
(
id
<
MASConstraint
>
(
^
)(
id
))
greaterThanOrEqualTo
{
return
[
self
relationWithBlock
:
^
id
<
MASConstraint
>
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
constraint
.
greaterThanOrEqualTo
(
attr
)
;
}];
return
^
id
(
id
attr
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
greaterThanOrEqualTo
(
attr
);
}
return
self
;
};
}
-
(
id
<
MASConstraint
>
(
^
)(
id
))
lessThanOrEqualTo
{
return
[
self
relationWithBlock
:
^
id
<
MASConstraint
>
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
constraint
.
lessThanOrEqualTo
(
attr
)
;
}];
return
^
id
(
id
attr
)
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
constraint
.
lessThanOrEqualTo
(
attr
);
}
return
self
;
};
}
#pragma mark - Semantic properties
...
...
@@ -192,10 +186,6 @@
#pragma mark - MASConstraint
-
(
void
)
commit
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
completedChildConstraints
)
{
[
constraint
commit
];
}
[
self
.
completedChildConstraints
removeAllObjects
];
}
@end
...
...
MasonryTests/MASCompositeConstraintSpec.m
View file @
c52bb5a
...
...
@@ -11,8 +11,7 @@
@interface
MASCompositeConstraint
()
<
MASConstraintDelegate
>
@property
(
nonatomic
,
strong
)
NSMutableArray
*
completedChildConstraints
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
currentChildConstraints
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
childConstraints
;
@property
(
nonatomic
,
assign
)
BOOL
added
;
@end
...
...
@@ -42,13 +41,13 @@ beforeEach(^{
it
(
@"should create centerY and centerX children"
,
^
{
composite
=
[[
MASCompositeConstraint
alloc
]
initWithView
:
view
type
:
MASCompositeViewConstraintTypeCenter
];
expect
(
composite
.
c
urrentC
hildConstraints
).
to
.
haveCountOf
(
2
);
expect
(
composite
.
childConstraints
).
to
.
haveCountOf
(
2
);
MASViewConstraint
*
viewConstraint
=
composite
.
c
urrentC
hildConstraints
[
0
];
MASViewConstraint
*
viewConstraint
=
composite
.
childConstraints
[
0
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeCenterX
);
viewConstraint
=
composite
.
c
urrentC
hildConstraints
[
1
];
viewConstraint
=
composite
.
childConstraints
[
1
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeCenterY
);
});
...
...
@@ -58,38 +57,38 @@ it(@"should create top, left, bottom, right children", ^{
composite
=
[[
MASCompositeConstraint
alloc
]
initWithView
:
view
type
:
MASCompositeViewConstraintTypeEdges
];
composite
.
equalTo
(
newView
);
expect
(
composite
.
c
ompletedC
hildConstraints
).
to
.
haveCountOf
(
4
);
expect
(
composite
.
childConstraints
).
to
.
haveCountOf
(
4
);
//top
MASViewConstraint
*
viewConstraint
=
composite
.
c
ompletedC
hildConstraints
[
0
];
MASViewConstraint
*
viewConstraint
=
composite
.
childConstraints
[
0
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeTop
);
//left
viewConstraint
=
composite
.
c
ompletedC
hildConstraints
[
1
];
viewConstraint
=
composite
.
childConstraints
[
1
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeLeft
);
//bottom
viewConstraint
=
composite
.
c
ompletedC
hildConstraints
[
2
];
viewConstraint
=
composite
.
childConstraints
[
2
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeBottom
);
//right
viewConstraint
=
composite
.
c
ompletedC
hildConstraints
[
3
];
viewConstraint
=
composite
.
childConstraints
[
3
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeRight
);
});
it
(
@"should create width and height children"
,
^
{
composite
=
[[
MASCompositeConstraint
alloc
]
initWithView
:
view
type
:
MASCompositeViewConstraintTypeSize
];
expect
(
composite
.
c
urrentC
hildConstraints
).
to
.
haveCountOf
(
2
);
expect
(
composite
.
childConstraints
).
to
.
haveCountOf
(
2
);
MASViewConstraint
*
viewConstraint
=
composite
.
c
urrentC
hildConstraints
[
0
];
MASViewConstraint
*
viewConstraint
=
composite
.
childConstraints
[
0
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeWidth
);
viewConstraint
=
composite
.
c
urrentC
hildConstraints
[
1
];
viewConstraint
=
composite
.
childConstraints
[
1
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeHeight
);
});
...
...
@@ -102,24 +101,19 @@ it(@"should complete children", ^{
//first equality statement
composite
.
equalTo
(
newView
).
sizeOffset
(
CGSizeMake
(
90
,
30
));
expect
(
composite
.
completedChildConstraints
).
to
.
haveCountOf
(
2
);
expect
(
composite
.
currentChildConstraints
).
to
.
haveCountOf
(
2
);
expect
(
composite
.
childConstraints
).
to
.
haveCountOf
(
2
);
MASViewConstraint
*
viewConstraint
=
composite
.
c
ompletedC
hildConstraints
[
0
];
MASViewConstraint
*
viewConstraint
=
composite
.
childConstraints
[
0
];
expect
(
viewConstraint
.
secondViewAttribute
.
view
).
to
.
beIdenticalTo
(
newView
);
expect
(
viewConstraint
.
secondViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeWidth
);
expect
(
viewConstraint
.
layoutConstant
).
to
.
equal
(
90
);
expect
(
viewConstraint
.
layoutPriority
).
to
.
equal
(
MASLayoutPriorityRequired
);
viewConstraint
=
composite
.
c
ompletedC
hildConstraints
[
1
];
viewConstraint
=
composite
.
childConstraints
[
1
];
expect
(
viewConstraint
.
secondViewAttribute
.
view
).
to
.
beIdenticalTo
(
newView
);
expect
(
viewConstraint
.
secondViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeHeight
);
expect
(
viewConstraint
.
layoutConstant
).
to
.
equal
(
30
);
expect
(
viewConstraint
.
layoutPriority
).
to
.
equal
(
MASLayoutPriorityRequired
);
//new current
expect
(
composite
.
completedChildConstraints
[
0
]).
to
.
beIdenticalTo
(
composite
.
currentChildConstraints
[
0
]);
expect
(
composite
.
completedChildConstraints
[
1
]).
to
.
beIdenticalTo
(
composite
.
currentChildConstraints
[
1
]);
});
it
(
@"should remove completed on commit"
,
^
{
...
...
@@ -131,15 +125,10 @@ it(@"should remove completed on commit", ^{
//first equality statement
composite
.
equalTo
(
newView
).
sizeOffset
(
CGSizeMake
(
90
,
30
));
[
verify
(
delegate
)
addConstraint
:(
id
)
composite
];
expect
(
composite
.
completedChildConstraints
).
to
.
haveCountOf
(
2
);
expect
(
composite
.
currentChildConstraints
).
to
.
haveCountOf
(
2
);
[
composite
commit
];
expect
(
composite
.
completedChildConstraints
).
to
.
haveCountOf
(
0
);
expect
(
composite
.
currentChildConstraints
).
to
.
haveCountOf
(
2
);
[
verify
(
delegate
)
addConstraint
:(
id
)
composite
.
childConstraints
[
0
]];
[
verify
(
delegate
)
addConstraint
:(
id
)
composite
.
childConstraints
[
1
]];
});
SpecEnd
\ No newline at end of file
...
...
Please
register
or
login
to post a comment