diff --git a/CHANGELOG.md b/CHANGELOG.md index b4858a5b..78e53256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa ## Upcoming release +### Fixed + +- Fixed `LocationMessageCell` reuse bug, to avoid inconsistency when get capture image asynchronously. +[#428](https://github.com/MessageKit/MessageKit/pull/428) by [@zhongwuzw](https://github.com/zhongwuzw). + ## [[Prerelease] 0.12.0](https://github.com/MessageKit/MessageKit/releases/tag/0.12.0) ### Added diff --git a/Sources/Views/Cells/LocationMessageCell.swift b/Sources/Views/Cells/LocationMessageCell.swift index 2368ad4e..b7721242 100644 --- a/Sources/Views/Cells/LocationMessageCell.swift +++ b/Sources/Views/Cells/LocationMessageCell.swift @@ -34,6 +34,8 @@ open class LocationMessageCell: MessageCollectionViewCell { open var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) open var imageView = UIImageView() + + private weak var snapShotter: MKMapSnapshotter? open override func setupSubviews() { super.setupSubviews() @@ -47,6 +49,11 @@ open class LocationMessageCell: MessageCollectionViewCell { imageView.fillSuperview() activityIndicator.centerInSuperview() } + + open override func prepareForReuse() { + super.prepareForReuse() + snapShotter?.cancel() + } open override func configure(with message: MessageType, at indexPath: IndexPath, and messagesCollectionView: MessagesCollectionView) { super.configure(with: message, at: indexPath, and: messagesCollectionView) @@ -67,6 +74,7 @@ open class LocationMessageCell: MessageCollectionViewCell { snapshotOptions.showsPointsOfInterest = options.showsPointsOfInterest let snapShotter = MKMapSnapshotter(options: snapshotOptions) + self.snapShotter = snapShotter snapShotter.start { (snapshot, error) in defer { self.activityIndicator.stopAnimating()