Fix LocationMessageCell reuse bug

This commit is contained in:
zhongwuzw
2017-12-29 14:33:44 +08:00
parent 70244ba702
commit d96d7efb58
2 changed files with 13 additions and 0 deletions
+5
View File
@@ -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
@@ -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()