From 2138b3ba5d2510ce62fe1c41d7ea94bdad7653d3 Mon Sep 17 00:00:00 2001 From: Nathan Tannar Date: Tue, 26 Mar 2019 12:20:11 -0700 Subject: [PATCH] Small changes to try and fix crash --- .../AdvancedExampleViewController.swift | 4 +-- MessageKit.podspec~ | 27 ------------------- .../MessagesCollectionViewFlowLayout.swift | 10 ++++--- 3 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 MessageKit.podspec~ diff --git a/Example/Sources/View Controllers/AdvancedExampleViewController.swift b/Example/Sources/View Controllers/AdvancedExampleViewController.swift index d8c87507..88955154 100644 --- a/Example/Sources/View Controllers/AdvancedExampleViewController.swift +++ b/Example/Sources/View Controllers/AdvancedExampleViewController.swift @@ -183,8 +183,8 @@ final class AdvancedExampleViewController: ChatViewController { func setTypingIndicatorViewHidden(_ isHidden: Bool, performUpdates updates: (() -> Void)? = nil) { updateTitleView(title: "MessageKit", subtitle: isHidden ? "2 Online" : "Typing...") - setTypingIndicatorViewHidden(isHidden, animated: true, whilePerforming: updates) { [weak self] (_) in - if self?.isLastSectionVisible() == true { + setTypingIndicatorViewHidden(isHidden, animated: true, whilePerforming: updates) { [weak self] success in + if success, self?.isLastSectionVisible() == true { self?.messagesCollectionView.scrollToBottom(animated: true) } } diff --git a/MessageKit.podspec~ b/MessageKit.podspec~ deleted file mode 100644 index 4a4007e6..00000000 --- a/MessageKit.podspec~ +++ /dev/null @@ -1,27 +0,0 @@ -Pod::Spec.new do |s| - s.name = 'MessageKit' - s.version = '3.0.0' - s.license = { :type => "MIT", :file => "LICENSE.md" } - - s.summary = 'An elegant messages UI library for iOS.' - s.homepage = 'https://github.com/MessageKit/MessageKit' - s.social_media_url = 'https://twitter.com/_SD10_' - s.author = { "Steven Deutsch" => "stevensdeutsch@yahoo.com" } - - s.source = { :git => 'https://github.com/MessageKit/MessageKit.git', :tag => s.version } - s.source_files = 'Sources/**/*.swift' - - s.pod_target_xcconfig = { - "SWIFT_VERSION" => "4.2", - } - - s.swift_version = '4.2' - - s.ios.deployment_target = '9.0' - s.ios.resource_bundle = { 'MessageKitAssets' => 'Assets/MessageKitAssets.bundle/Images' } - - s.requires_arc = true - - s.dependency 'InputBarAccessoryView' - -end diff --git a/Sources/Layout/MessagesCollectionViewFlowLayout.swift b/Sources/Layout/MessagesCollectionViewFlowLayout.swift index 451384e1..9162f90c 100644 --- a/Sources/Layout/MessagesCollectionViewFlowLayout.swift +++ b/Sources/Layout/MessagesCollectionViewFlowLayout.swift @@ -117,7 +117,10 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout { /// - completion: A completion block to execute after the insertion/deletion open func setTypingIndicatorViewHidden(_ isHidden: Bool, animated: Bool, whilePerforming updates: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { - guard isTypingIndicatorViewHidden != isHidden else { return } + guard isTypingIndicatorViewHidden != isHidden, messagesCollectionView.numberOfSections > 0 else { + completion?(false) + return + } isTypingIndicatorViewHidden = isHidden let ctx = UICollectionViewFlowLayoutInvalidationContext() @@ -125,13 +128,14 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout { ofKind: MessagesCollectionView.elementKindTypingIndicator, at: [indexPathForTypingIndicatorView()] ) - invalidateLayout(with: ctx) if animated { messagesCollectionView.performBatchUpdates({ [weak self] in + self?.invalidateLayout(with: ctx) updates?() }, completion: completion) } else { + invalidateLayout(with: ctx) updates?() completion?(true) } @@ -203,7 +207,7 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout { private func indexPathForTypingIndicatorView() -> IndexPath { let section = messagesCollectionView.numberOfSections - 2 - return IndexPath(row: 0, section: max(section, 0)) + return IndexPath(item: 0, section: max(section, 0)) } // MARK: - Layout Invalidation