Commit 223faaa9 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Fix ReadingList swipe-to-delete on iOS 10.

On iOS 10, UITableView will attempt to reload the deleted row's section
after the animation, regardless of whether it's been removed from the
UITableViewDataSource.  This CL prevents that from occurring by
performing a full reload when sections are deleted for swipe gestures
on iOS 10.

Bug: 898841
Change-Id: Ib35089be7982d040ad4e71a4b1759495dd7b8345
Reviewed-on: https://chromium-review.googlesource.com/c/1300106
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604246}
parent f4c1c0e7
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/reading_list/reading_list_table_view_controller.h"
#include "base/ios/ios_util.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/metrics/histogram_macros.h"
......@@ -137,7 +138,21 @@ ReadingListSelectionState GetSelectionStateForSelectedCounts(
if (!editing) {
self.editingWithToolbarButtons = NO;
if (self.needsSectionCleanupAfterEditing) {
[self removeEmptySections];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
// |removedSectionCount| is only used in iOS10, so unused variable
// warnings should be ignored in order to allow compilation until the
// iOS10 fix is removed.
NSUInteger removedSectionCount = [self removeEmptySections];
#pragma clang diagnostic pop
#if !defined(__IPHONE_11_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_11_0
// The swipe-to-delete gesture on iOS 10 erroneously attempts to reload
// deleted row's section upon completion of its animation, regardless of
// whether the row was the last in the section. If the section was
// removed force a full table reload so that the updated model is used.
if (removedSectionCount && !base::ios::IsRunningOnIOS11OrLater())
[self.tableView reloadData];
#endif
self.needsSectionCleanupAfterEditing = NO;
}
}
......@@ -860,10 +875,12 @@ ReadingListSelectionState GetSelectionStateForSelectedCounts(
[self removeEmptySections];
}
// Removes the empty sections from the table and the model.
- (void)removeEmptySections {
// Removes the empty sections from the table and the model. Returns the number
// of removed sections.
- (NSUInteger)removeEmptySections {
UITableView* tableView = self.tableView;
TableViewModel* model = self.tableViewModel;
__block NSUInteger removedSectionCount = 0;
void (^updates)(void) = ^{
SectionIdentifier sections[] = {SectionIdentifierRead,
SectionIdentifierUnread};
......@@ -878,6 +895,7 @@ ReadingListSelectionState GetSelectionStateForSelectedCounts(
[tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
[model removeSectionWithIdentifier:section];
++removedSectionCount;
}
}
};
......@@ -887,6 +905,8 @@ ReadingListSelectionState GetSelectionStateForSelectedCounts(
[self tableIsEmpty];
else
[self updateToolbarItems];
return removedSectionCount;
}
// Resets self.editing to NO, optionally with animation.
......
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