Commit e365896e authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] reload hidden ntps when suggestions visibility is toggled

Bug: 1110827
Change-Id: I52c9ee5015fcb9cc61f4060473797a00614446f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362811
Auto-Submit: David Jean <djean@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799534}
parent 705d92d1
...@@ -418,13 +418,13 @@ const NSInteger kMaxNumMostVisitedTiles = 4; ...@@ -418,13 +418,13 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
- (void)toggleArticlesVisibility { - (void)toggleArticlesVisibility {
[self.contentArticlesExpanded setValue:![self.contentArticlesExpanded value]]; [self.contentArticlesExpanded setValue:![self.contentArticlesExpanded value]];
[self reloadArticleSection]; [self reloadArticleSectionOrAllData:NO];
} }
#pragma mark - BooleanObserver #pragma mark - BooleanObserver
- (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean {
[self reloadArticleSection]; [self reloadArticleSectionOrAllData:YES];
} }
#pragma mark - ContentSuggestionsServiceObserver #pragma mark - ContentSuggestionsServiceObserver
...@@ -606,7 +606,10 @@ const NSInteger kMaxNumMostVisitedTiles = 4; ...@@ -606,7 +606,10 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
#pragma mark - Private #pragma mark - Private
- (void)reloadArticleSection { // Reloads article section (for the page that trigers the request) or all
// for other tabs/windows observing the pref. It avoids issues with scroll
// changes, in hidden tabs/windows which leads to crashes.
- (void)reloadArticleSectionOrAllData:(BOOL)allData {
// Update the section information for new collapsed state. // Update the section information for new collapsed state.
ntp_snippets::Category category = ntp_snippets::Category::FromKnownCategory( ntp_snippets::Category category = ntp_snippets::Category::FromKnownCategory(
ntp_snippets::KnownCategories::ARTICLES); ntp_snippets::KnownCategories::ARTICLES);
...@@ -616,12 +619,16 @@ const NSInteger kMaxNumMostVisitedTiles = 4; ...@@ -616,12 +619,16 @@ const NSInteger kMaxNumMostVisitedTiles = 4;
self.sectionInformationByCategory[wrapper]; self.sectionInformationByCategory[wrapper];
sectionInfo.expanded = [self.contentArticlesExpanded value]; sectionInfo.expanded = [self.contentArticlesExpanded value];
// Reloading the section with animations looks bad because the section if (allData) {
// border with the new collapsed height draws before the elements collapse. [self reloadAllData];
BOOL animationsWereEnabled = [UIView areAnimationsEnabled]; } else {
[UIView setAnimationsEnabled:NO]; // Reloading the section with animations looks bad because the section
[self.dataSink reloadSection:sectionInfo]; // border with the new collapsed height draws before the elements collapse.
[UIView setAnimationsEnabled:animationsWereEnabled]; BOOL animationsWereEnabled = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[self.dataSink reloadSection:sectionInfo];
[UIView setAnimationsEnabled:animationsWereEnabled];
}
} }
// Converts the |suggestions| from |category| to CSCollectionViewItem and adds // Converts the |suggestions| from |category| to CSCollectionViewItem and adds
......
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