Reuse cover views when rebuilding sticker management table

Creating fresh cover views resets the animation playback and causes
weird flicker. If we just cache the views that we're already using then
we can avoid the flicker.

Eventually we should move this table towards reusable cells, but until
then, reusable image views will have to do.
This commit is contained in:
Michelle Linington 2021-01-23 05:50:52 -08:00
parent 9fdd3ffcd3
commit d51bb201d6

View File

@ -123,6 +123,7 @@ public class ManageStickersViewController: OWSTableViewController {
private var installedStickerPackSources = [StickerPackDataSource]()
private var availableBuiltInStickerPackSources = [StickerPackDataSource]()
private var knownStickerPackSources = [StickerPackDataSource]()
private var coverInfoViewCache = [Data: UIView]()
private func updateState() {
// If we're presenting a modal because the user tapped install, dismiss it.
@ -343,10 +344,11 @@ public class ManageStickersViewController: OWSTableViewController {
let authorNameValue: String? = dataSource.author?.filterForDisplay
let iconView: UIView
if let stickerInfo = stickerInfo,
let coverView = imageView(forStickerInfo: stickerInfo,
dataSource: dataSource) {
if let stickerInfo = stickerInfo, let cachedView = coverInfoViewCache[stickerInfo.packId] {
iconView = cachedView
} else if let stickerInfo = stickerInfo, let coverView = imageView(forStickerInfo: stickerInfo, dataSource: dataSource) {
iconView = coverView
coverInfoViewCache[stickerInfo.packId] = coverView
} else {
iconView = UIView()
}