Commit 59bbe5cc authored by sczs's avatar sczs Committed by Commit Bot

[ios Checks ContentSuggestions KVO flag before any KVO change

Bug: 1122031
Change-Id: Ie2733764f57d824cb9bf61155c69ddb248e4c704
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2468715Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816793}
parent e4faf304
......@@ -125,10 +125,7 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
}
- (void)dealloc {
if (self.observingDiscoverFeedHeight) {
[self.feedView removeObserver:self forKeyPath:@"contentSize"];
self.observingDiscoverFeedHeight = NO;
}
[self removeContentSizeKVO];
if (self.discoverFeedVC.parentViewController) {
[self.discoverFeedVC willMoveToParentViewController:nil];
[self.discoverFeedVC.view removeFromSuperview];
......@@ -442,8 +439,7 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
// If previous VC is not nil, remove it from the view hierarchy and stop
// osberving its feedView.
if (self.discoverFeedVC) {
[self.feedView removeObserver:self forKeyPath:@"contentSize"];
self.observingDiscoverFeedHeight = NO;
[self removeContentSizeKVO];
[self.discoverFeedVC willMoveToParentViewController:nil];
[self.discoverFeedVC.view removeFromSuperview];
[self.discoverFeedVC removeFromParentViewController];
......@@ -462,11 +458,7 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
self.feedView = static_cast<UICollectionView*>(view);
}
}
[self.feedView addObserver:self
forKeyPath:@"contentSize"
options:0
context:nil];
self.observingDiscoverFeedHeight = YES;
[self addContentSizeKVO];
self.discoverFeedVC = newFeedViewController;
return cell;
}
......@@ -841,6 +833,25 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
#pragma mark - Private
// Adds KVO observing for the feedView contentSize if there is not one already.
- (void)addContentSizeKVO {
if (!self.observingDiscoverFeedHeight) {
[self.feedView addObserver:self
forKeyPath:@"contentSize"
options:0
context:nil];
self.observingDiscoverFeedHeight = YES;
}
}
// Removes KVO observing for the feedView contentSize if one exists.
- (void)removeContentSizeKVO {
if (self.observingDiscoverFeedHeight) {
[self.feedView removeObserver:self forKeyPath:@"contentSize"];
self.observingDiscoverFeedHeight = NO;
}
}
- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer {
if (self.editor.editing ||
gestureRecognizer.state != UIGestureRecognizerStateBegan) {
......
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