Commit d39cc774 authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[CRD iOS] Fixing an infinite layout loop

On iOS 9, it seems the [self updateFABConstraintsAnimated:NO] call in
viewDidLayoutSubviews and [self layoutIfNeeded] call in
updateFABConstraintsAnimated causes an infinite layout loop, which
crashes the app right after the HostViewController appears due to
stack overflow.

This CL fixes this problem by removing the
updateFABConstraintsAnimated: call from viewDidLayoutSubviews.


Bug: 769533
Change-Id: I311d9168db4bcae097455eb27a908c086de71572
Reviewed-on: https://chromium-review.googlesource.com/687829Reviewed-by: default avatarScott Nichols <nicholss@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505152}
parent 1314c931
......@@ -46,6 +46,8 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
CGSize _keyboardSize;
BOOL _surfaceCreated;
HostSettings* _settings;
// Only change this by calling setFabIsRight:.
BOOL _fabIsRight;
NSArray<NSLayoutConstraint*>* _fabLeftConstraints;
NSArray<NSLayoutConstraint*>* _fabRightConstraints;
......@@ -86,13 +88,11 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
[_surfaceSizeAnimationLink addToRunLoop:NSRunLoop.currentRunLoop
forMode:NSDefaultRunLoopMode];
if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:
BOOL fabIsRight =
[UIView userInterfaceLayoutDirectionForSemanticContentAttribute:
self.view.semanticContentAttribute] ==
UIUserInterfaceLayoutDirectionRightToLeft) {
_fabIsRight = NO;
} else {
_fabIsRight = YES;
}
UIUserInterfaceLayoutDirectionLeftToRight;
[self setFabIsRight:fabIsRight shouldLayout:NO];
}
return self;
}
......@@ -241,8 +241,6 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
_surfaceSizeAnimationLink.paused = NO;
[self resizeHostToFitIfNeeded];
[self updateFABConstraintsAnimated:NO];
}
#pragma mark - Keyboard Notifications
......@@ -332,13 +330,14 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
}
- (void)moveFAB {
_fabIsRight = !_fabIsRight;
[self updateFABConstraintsAnimated:YES];
[self setFabIsRight:!_fabIsRight shouldLayout:YES];
}
#pragma mark - Private
- (void)updateFABConstraintsAnimated:(BOOL)animated {
- (void)setFabIsRight:(BOOL)fabIsRight shouldLayout:(BOOL)shouldLayout {
_fabIsRight = fabIsRight;
[NSLayoutConstraint deactivateConstraints:_fabRightConstraints];
[NSLayoutConstraint deactivateConstraints:_fabLeftConstraints];
if (_fabIsRight) {
......@@ -347,13 +346,11 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
[NSLayoutConstraint activateConstraints:_fabLeftConstraints];
}
if (animated) {
if (shouldLayout) {
[UIView animateWithDuration:kMoveFABAnimationTime
animations:^{
[self.view layoutIfNeeded];
}];
} else {
[self.view layoutIfNeeded];
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment