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; ...@@ -46,6 +46,8 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
CGSize _keyboardSize; CGSize _keyboardSize;
BOOL _surfaceCreated; BOOL _surfaceCreated;
HostSettings* _settings; HostSettings* _settings;
// Only change this by calling setFabIsRight:.
BOOL _fabIsRight; BOOL _fabIsRight;
NSArray<NSLayoutConstraint*>* _fabLeftConstraints; NSArray<NSLayoutConstraint*>* _fabLeftConstraints;
NSArray<NSLayoutConstraint*>* _fabRightConstraints; NSArray<NSLayoutConstraint*>* _fabRightConstraints;
...@@ -86,13 +88,11 @@ static const CGFloat kMoveFABAnimationTime = 0.3; ...@@ -86,13 +88,11 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
[_surfaceSizeAnimationLink addToRunLoop:NSRunLoop.currentRunLoop [_surfaceSizeAnimationLink addToRunLoop:NSRunLoop.currentRunLoop
forMode:NSDefaultRunLoopMode]; forMode:NSDefaultRunLoopMode];
if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute: BOOL fabIsRight =
[UIView userInterfaceLayoutDirectionForSemanticContentAttribute:
self.view.semanticContentAttribute] == self.view.semanticContentAttribute] ==
UIUserInterfaceLayoutDirectionRightToLeft) { UIUserInterfaceLayoutDirectionLeftToRight;
_fabIsRight = NO; [self setFabIsRight:fabIsRight shouldLayout:NO];
} else {
_fabIsRight = YES;
}
} }
return self; return self;
} }
...@@ -241,8 +241,6 @@ static const CGFloat kMoveFABAnimationTime = 0.3; ...@@ -241,8 +241,6 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
_surfaceSizeAnimationLink.paused = NO; _surfaceSizeAnimationLink.paused = NO;
[self resizeHostToFitIfNeeded]; [self resizeHostToFitIfNeeded];
[self updateFABConstraintsAnimated:NO];
} }
#pragma mark - Keyboard Notifications #pragma mark - Keyboard Notifications
...@@ -332,13 +330,14 @@ static const CGFloat kMoveFABAnimationTime = 0.3; ...@@ -332,13 +330,14 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
} }
- (void)moveFAB { - (void)moveFAB {
_fabIsRight = !_fabIsRight; [self setFabIsRight:!_fabIsRight shouldLayout:YES];
[self updateFABConstraintsAnimated:YES];
} }
#pragma mark - Private #pragma mark - Private
- (void)updateFABConstraintsAnimated:(BOOL)animated { - (void)setFabIsRight:(BOOL)fabIsRight shouldLayout:(BOOL)shouldLayout {
_fabIsRight = fabIsRight;
[NSLayoutConstraint deactivateConstraints:_fabRightConstraints]; [NSLayoutConstraint deactivateConstraints:_fabRightConstraints];
[NSLayoutConstraint deactivateConstraints:_fabLeftConstraints]; [NSLayoutConstraint deactivateConstraints:_fabLeftConstraints];
if (_fabIsRight) { if (_fabIsRight) {
...@@ -347,13 +346,11 @@ static const CGFloat kMoveFABAnimationTime = 0.3; ...@@ -347,13 +346,11 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
[NSLayoutConstraint activateConstraints:_fabLeftConstraints]; [NSLayoutConstraint activateConstraints:_fabLeftConstraints];
} }
if (animated) { if (shouldLayout) {
[UIView animateWithDuration:kMoveFABAnimationTime [UIView animateWithDuration:kMoveFABAnimationTime
animations:^{ animations:^{
[self.view layoutIfNeeded]; [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