Commit 457cbfbe authored by edchin's avatar edchin Committed by Commit Bot

[ios] Fix crash in tab grid animator

The tab grid animator relies on the condition that
BVCContainerViewController only has one subview which has
the named guide it needs. However, crbug.com/1053452 shows
this is condition is not always met.

Tab grid animator should not be the unwitting enforcer that
BVCContainerViewController does not contain superfluous subviews.
Tab grid animator should just find the named guide it needs.
If BVCContainerViewController having other subviews is a problem,
that invariant should be enforced somewhere other than in
this animator.

Bug: 1053452, 860234
Change-Id: I4a622920301998e8d3211039c6594a637ad54bf5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2112139
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#752032}
parent 2e124393
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/tab_grid/transitions/legacy_tab_to_grid_animator.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_animation_layout_providing.h"
#import "ios/chrome/browser/ui/tab_grid/transitions/grid_transition_layout.h"
......@@ -83,13 +84,23 @@
// view; rather it's the view of the view controller that contains the BVC.
// Unfortunatley, the layout guide needed here is attached to the BVC's view,
// which is the first (and only) subview of the BVCContainerViewController's
// view.
// view in most cases. However, crbug.com/1053452 shows that we cannot just
// blindly use the first subview. The for-loop below ensures that a layout
// guide is obtained from the first subview that has it.
// TODO(crbug.com/860234) Clean up this arrangement.
UIView* viewWithNamedGuides = dismissingView.subviews[0];
CGRect initialRect = [NamedGuide guideWithName:kContentAreaGuide
view:viewWithNamedGuides]
.layoutFrame;
UIView* viewWithNamedGuides = nil;
CGRect initialRect;
for (viewWithNamedGuides in dismissingView.subviews) {
NamedGuide* namedGuide = [NamedGuide guideWithName:kContentAreaGuide
view:viewWithNamedGuides];
if (namedGuide) {
initialRect = namedGuide.layoutFrame;
break;
}
}
// Prefer to crash here at the root cause, rather than crashing later where
// the reason is more ambiguous.
CHECK_NE(nil, viewWithNamedGuides);
[layout.activeItem populateWithSnapshotsFromView:viewWithNamedGuides
middleRect:initialRect];
......
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