From ffed8af857da2ae4cb8e4e20ec6bba08d93cb86c Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Mon, 24 Jul 2017 13:56:24 -0600 Subject: [PATCH] scroll to bottom when posting new comments --- Classes/Issues/IssuesViewController.swift | 7 +++++-- .../Views/UIScrollView+ScrollToBottom.swift | 21 +++++++++++++++++++ Freetime.xcodeproj/project.pbxproj | 4 ++++ Resources/Info.plist | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 Classes/Views/UIScrollView+ScrollToBottom.swift diff --git a/Classes/Issues/IssuesViewController.swift b/Classes/Issues/IssuesViewController.swift index 951fc8c8..9e20c165 100644 --- a/Classes/Issues/IssuesViewController.swift +++ b/Classes/Issues/IssuesViewController.swift @@ -65,7 +65,6 @@ IssueCommentAutocompleteDelegate { // override default SLKTextViewController values isInverted = false - shouldScrollToBottomAfterKeyboardShows = true textView.placeholder = NSLocalizedString("Leave a comment", comment: "") textView.keyboardType = .default rightButton.setTitle(NSLocalizedString("Send", comment: ""), for: .normal) @@ -238,7 +237,11 @@ IssueCommentAutocompleteDelegate { ) else { return } models.append(comment) - feed.adapter.performUpdates(animated: true) + + let collectionView = feed.collectionView + feed.adapter.performUpdates(animated: false, completion: { _ in + collectionView.slk_scrollToBottom(animated: true) + }) } func didFailSendingComment(client: AddCommentClient) {} diff --git a/Classes/Views/UIScrollView+ScrollToBottom.swift b/Classes/Views/UIScrollView+ScrollToBottom.swift new file mode 100644 index 00000000..7ae54dd4 --- /dev/null +++ b/Classes/Views/UIScrollView+ScrollToBottom.swift @@ -0,0 +1,21 @@ +// +// UIScrollView+ScrollToBottom.swift +// Freetime +// +// Created by Ryan Nystrom on 7/24/17. +// Copyright © 2017 Ryan Nystrom. All rights reserved. +// + +import UIKit + +extension UIScrollView { + + func scrollToBottom(animated: Bool) { + let inset = contentInset + let contentHeight = contentSize.height + let viewportHeight = bounds.height + let offset = contentHeight - inset.bottom + inset.top - viewportHeight + setContentOffset(CGPoint(x: 0, y: offset), animated: animated) + } + +} diff --git a/Freetime.xcodeproj/project.pbxproj b/Freetime.xcodeproj/project.pbxproj index 8e455d87..8b4a91cc 100644 --- a/Freetime.xcodeproj/project.pbxproj +++ b/Freetime.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 290744B51F250A6800FD9E48 /* EmojiAutocomplete.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290744B21F250A6800FD9E48 /* EmojiAutocomplete.swift */; }; 290744B61F250A6800FD9E48 /* IssueCommentAutocomplete.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290744B31F250A6800FD9E48 /* IssueCommentAutocomplete.swift */; }; 290744B81F250A7200FD9E48 /* AutocompleteType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290744B71F250A7200FD9E48 /* AutocompleteType.swift */; }; + 290744BA1F26863100FD9E48 /* UIScrollView+ScrollToBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290744B91F26863100FD9E48 /* UIScrollView+ScrollToBottom.swift */; }; 290D2A3D1F044CB20082E6CC /* UIViewController+SmartDeselection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290D2A3C1F044CB20082E6CC /* UIViewController+SmartDeselection.swift */; }; 290D2A3F1F0466820082E6CC /* NotificationNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290D2A3E1F0466820082E6CC /* NotificationNavigation.swift */; }; 290D2A421F04D3470082E6CC /* IssueStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290D2A411F04D3470082E6CC /* IssueStatus.swift */; }; @@ -377,6 +378,7 @@ 290744B21F250A6800FD9E48 /* EmojiAutocomplete.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmojiAutocomplete.swift; sourceTree = ""; }; 290744B31F250A6800FD9E48 /* IssueCommentAutocomplete.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueCommentAutocomplete.swift; sourceTree = ""; }; 290744B71F250A7200FD9E48 /* AutocompleteType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutocompleteType.swift; sourceTree = ""; }; + 290744B91F26863100FD9E48 /* UIScrollView+ScrollToBottom.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIScrollView+ScrollToBottom.swift"; sourceTree = ""; }; 290D2A3C1F044CB20082E6CC /* UIViewController+SmartDeselection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+SmartDeselection.swift"; sourceTree = ""; }; 290D2A3E1F0466820082E6CC /* NotificationNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationNavigation.swift; sourceTree = ""; }; 290D2A411F04D3470082E6CC /* IssueStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueStatus.swift; sourceTree = ""; }; @@ -1105,6 +1107,7 @@ 29A195011EC66B8B00C3E289 /* UIColor+Hex.swift */, 29A4769F1ED0E6C6005D0953 /* UIColor+Overlay.swift */, 298BA08E1EC90FEE00B01946 /* UIView+BottomBorder.swift */, + 290744B91F26863100FD9E48 /* UIScrollView+ScrollToBottom.swift */, ); path = Views; sourceTree = ""; @@ -1482,6 +1485,7 @@ 292CD3D01F0DBB5C00D3D57B /* WebviewCellHeightCache.swift in Sources */, 295C31CF1F0AA67600521CED /* IssueStatus+ButtonState.swift in Sources */, 292FCAF81EDFCC510026635E /* CollapsibleCell.swift in Sources */, + 290744BA1F26863100FD9E48 /* UIScrollView+ScrollToBottom.swift in Sources */, 291F99D71EFFFA2600CFBF78 /* SettingsReportSectionController.swift in Sources */, 29CD71171EF22F4200616E85 /* NSAttributedString+Trim.swift in Sources */, 292FCB0F1EDFCC510026635E /* IssuesViewController.swift in Sources */, diff --git a/Resources/Info.plist b/Resources/Info.plist index 925ef98d..87a89bf0 100644 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -32,7 +32,7 @@ CFBundleVersion - 982 + 983 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes