Authored by Robert Payne

Re-work installed vs uninstalled state

These two API's now prefer to use activate/deactivate if available over our older custom install algorithm.
... ... @@ -288,24 +288,11 @@ static char kInstalledConstraintsKey;
#pragma mark - MASConstraint
- (void)activate {
if ([self supportsActiveProperty] && self.layoutConstraint) {
if (self.hasBeenInstalled) {
return;
}
self.layoutConstraint.active = YES;
[self.firstViewAttribute.view.mas_installedConstraints addObject:self];
} else {
[self install];
}
[self installedView];
}
- (void)deactivate {
if ([self supportsActiveProperty]) {
self.layoutConstraint.active = NO;
[self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
} else {
[self uninstall];
}
[self uninstall];
}
- (void)install {
... ... @@ -313,6 +300,12 @@ static char kInstalledConstraintsKey;
return;
}
if ([self supportsActiveProperty] && self.layoutConstraint) {
self.layoutConstraint.active = YES;
[self.firstViewAttribute.view.mas_installedConstraints addObject:self];
return;
}
MAS_VIEW *firstLayoutItem = self.firstViewAttribute.item;
NSLayoutAttribute firstLayoutAttribute = self.firstViewAttribute.layoutAttribute;
MAS_VIEW *secondLayoutItem = self.secondViewAttribute.item;
... ... @@ -387,6 +380,12 @@ static char kInstalledConstraintsKey;
}
- (void)uninstall {
if ([self supportsActiveProperty]) {
self.layoutConstraint.active = NO;
[self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
return;
}
[self.installedView removeConstraint:self.layoutConstraint];
self.layoutConstraint = nil;
self.installedView = nil;
... ...