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

[TIMOB-19808] iOS Autolayout - Fixed infinite layout loop #7568

Merged
merged 2 commits into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions iphone/Classes/Layout/TiLayoutView.m
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ -(void)updateWidthAndHeight
{
if ([superview isKindOfClass:[UITableView class]]) {
return;
} else if ([superview isKindOfClass:[UIScrollView class]])
}
else if ([superview isKindOfClass:[UIScrollView class]])
{
TiLayoutRemoveChildConstraints(superview, self);
[superview addConstraints: TI_CONSTR(@"V:|[self]|", viewsDict)];
Expand Down Expand Up @@ -766,12 +767,12 @@ -(void)updateMarginsForAbsoluteLayout:(TiLayoutView*)child
CGFloat bottomValue = TiDimensionCalculateValue(bottom, 1);

// ========= TI.UI.SIZE ============
if (IS_AUTOSIZE(_tiLayoutConstraint.width)) {
if (IS_AUTOSIZE(_tiLayoutConstraint.width) || (IS_UNDEFINED(_tiLayoutConstraint.width) && IS_AUTOSIZE(_defaultWidth))) {
[self addConstraints: TI_CONSTR( TI_STRING(@"H:|-(>=%f)-[child]-(>=%f)-|", leftValue, rightValue), viewsDict)];
} else if (_tiLayoutConstraint.width_isSet) {
[self removeConstraints: TI_CONSTR( TI_STRING(@"H:|-(>=%f)-[child]-(>=%f)-|", leftValue, rightValue), viewsDict)];
}
if (IS_AUTOSIZE(_tiLayoutConstraint.height)) {
if (IS_AUTOSIZE(_tiLayoutConstraint.height) || (IS_UNDEFINED(_tiLayoutConstraint.height) && IS_AUTOSIZE(_defaultHeight))) {
[self addConstraints: TI_CONSTR( TI_STRING(@"V:|-(>=%f)-[child]-(>=%f)-|", topValue, bottomValue), viewsDict)];
} else if (_tiLayoutConstraint.height_isSet) {
[self removeConstraints: TI_CONSTR( TI_STRING(@"V:|-(>=%f)-[child]-(>=%f)-|", topValue, bottomValue), viewsDict)];
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiUILabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ -(void)padLabel
#endif
}

#ifndef TI_USE_AUTOLAYOUT
// FIXME: This isn't quite true. But the brilliant soluton wasn't so brilliant, because it screwed with layout in unpredictable ways.
// Sadly, there was a brilliant solution for fixing the blurring here, but it turns out there's a
// quicker fix: Make sure the label itself has an even height and width. Everything else is irrelevant.
-(void)setCenter:(CGPoint)newCenter
{
[super setCenter:CGPointMake(floorf(newCenter.x), floorf(newCenter.y))];
}
#endif

-(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
{
Expand Down
2 changes: 1 addition & 1 deletion iphone/layout/Classes/TiLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

@interface TiLabel : TiLayoutView

-(void)setText:(NSString*) text;
@property (nonatomic, retain) NSString* text;
@end
1 change: 1 addition & 0 deletions iphone/layout/Classes/TiLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (instancetype)init

-(void)setText:(NSString*) text
{
_text = text;
[label setText:text];
}

Expand Down
8 changes: 4 additions & 4 deletions iphone/layout/Classes/TiScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ - (instancetype)init
[contentView setBackgroundColor:[UIColor greenColor]];
[contentView setViewName:@"TiScrollView.ContentView"];

[contentView setDefaultHeight:TiDimensionFromObject(@"SIZE")];
[contentView setDefaultWidth:TiDimensionFromObject(@"SIZE")];
[contentView setDefaultHeight:TiDimensionAutoSize];
[contentView setDefaultWidth:TiDimensionAutoSize];

[scrollView addSubview:contentView];

[self setDefaultHeight:TiDimensionFromObject(@"FILL")];
[self setDefaultWidth:TiDimensionFromObject(@"FILL")];
[self setDefaultHeight:TiDimensionAutoFill];
[self setDefaultWidth:TiDimensionAutoFill];

[super addSubview:scrollView];

Expand Down
6 changes: 4 additions & 2 deletions iphone/layout/layout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREFIX_HEADER = /Users/penrique/Desktop/layout/layout/layout.pch;
GCC_PREFIX_HEADER = $SRCROOT/layout/layout.pch;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand Down Expand Up @@ -414,7 +414,7 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREFIX_HEADER = /Users/penrique/Desktop/layout/layout/layout.pch;
GCC_PREFIX_HEADER = $SRCROOT/layout/layout.pch;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand Down Expand Up @@ -461,6 +461,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREFIX_HEADER = $SRCROOT/layout/layout.pch;
INFOPLIST_FILE = layoutTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.pec1985.layoutTests;
Expand All @@ -473,6 +474,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREFIX_HEADER = $SRCROOT/layout/layout.pch;
INFOPLIST_FILE = layoutTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.pec1985.layoutTests;
Expand Down
83 changes: 57 additions & 26 deletions iphone/layout/layout/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,67 @@ -(UIColor*) randomColor
- (void)viewDidLoad {
[super viewDidLoad];

TiLayoutView* myView = [[TiLayoutView alloc] init];
[[self view] addSubview:myView];

TiScrollableView* scrollable = [[TiScrollableView alloc] init];
[scrollable setViewName:@"scrollable"];
[scrollable setBackgroundColor:[UIColor grayColor]];
[scrollable setHeight_:@"SIZE"];

NSNumber* bigger = @300;
NSNumber* top = @10;
NSNumber* bottom = @5;
for (int i = 0; i < 5; i++) {
TiLayoutView* view = [[TiLayoutView alloc] init];
[view setBackgroundColor:[UIColor blueColor]];
if (i == 2) {
[view setHeight_:bigger];
[view setTop_:top];
[view setBottom_:bottom];
} else {
[view setHeight_:@200];
}
[view setWidth_:@200];
[scrollable addSubview:view];
}
TiLayoutView* window = [[TiLayoutView alloc] init];

[myView addSubview:scrollable];

[scrollable setOnLayout:^(TiLayoutView *sender, CGRect rect) {
{
TiScrollView* scrollView = [[TiScrollView alloc] init];
scrollView.top = @10;
scrollView.left = @10;
scrollView.width = @100;
scrollView.height = @150;
scrollView.backgroundColor = [UIColor greenColor];

TiLayoutView* view = [[TiLayoutView alloc] init];
view.width = @150;
view.height = @200;
view.top = @10;
view.backgroundColor = [UIColor grayColor];

}];
TiLabel* label = [[TiLabel alloc] init];
label.width = @"SIZE";
label.height = @"SIZE";
label.text = @"Bounce:true, vertbar:false";
label.backgroundColor = [UIColor yellowColor];



[view addSubview:label];
[scrollView addSubview:view];

[window addSubview:scrollView];
}

{
TiScrollView* scrollView = [[TiScrollView alloc] init];
scrollView.top = @10;
scrollView.right = @10;
scrollView.width = @100;
scrollView.height = @150;
scrollView.backgroundColor = [UIColor greenColor];

TiLayoutView* view = [[TiLayoutView alloc] init];
view.width = @150;
view.height = @200;
view.top = @10;
view.backgroundColor = [UIColor grayColor];

TiLabel* label = [[TiLabel alloc] init];
label.text = @"Bounce:true, horzbar:false";
label.width = @"SIZE";
label.height = @"SIZE";
label.backgroundColor = [UIColor yellowColor];



[view addSubview:label];
[scrollView addSubview:view];

[window addSubview:scrollView];
}

[[self view] addSubview:window];

}
@end