Fix auto scroll to bottom bug
This commit is contained in:
parent
397e12c14b
commit
44288c45e9
|
@ -5063,7 +5063,7 @@
|
||||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
CURRENT_PROJECT_VERSION = 270;
|
CURRENT_PROJECT_VERSION = 272;
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
||||||
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
||||||
|
@ -5132,7 +5132,7 @@
|
||||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
CURRENT_PROJECT_VERSION = 270;
|
CURRENT_PROJECT_VERSION = 272;
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
||||||
ENABLE_NS_ASSERTIONS = NO;
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
|
@ -5193,7 +5193,7 @@
|
||||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
CURRENT_PROJECT_VERSION = 270;
|
CURRENT_PROJECT_VERSION = 272;
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
||||||
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
||||||
|
@ -5263,7 +5263,7 @@
|
||||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
CURRENT_PROJECT_VERSION = 270;
|
CURRENT_PROJECT_VERSION = 272;
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
||||||
ENABLE_NS_ASSERTIONS = NO;
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
|
@ -6148,7 +6148,7 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
CURRENT_PROJECT_VERSION = 270;
|
CURRENT_PROJECT_VERSION = 272;
|
||||||
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
|
@ -6216,7 +6216,7 @@
|
||||||
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||||
CURRENT_PROJECT_VERSION = 270;
|
CURRENT_PROJECT_VERSION = 272;
|
||||||
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
DEVELOPMENT_TEAM = SUQ8J2PCT7;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
|
|
|
@ -18,10 +18,11 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleScrollToBottomButtonTapped() {
|
func handleScrollToBottomButtonTapped() {
|
||||||
// The tableview's content size will be calculated by the estimated height of cells,
|
// The table view's content size is calculated by the estimated height of cells,
|
||||||
// so the result may be inaccurate before all the cells are loaded.
|
// so the result may be inaccurate before all the cells are loaded. Use this
|
||||||
// Use this scroll to the last row instead.
|
// to scroll to the last row instead.
|
||||||
messagesTableView.scrollToRow(at: IndexPath(row: viewItems.count-1, section: 0), at: .top, animated: true)
|
let indexPath = IndexPath(row: viewItems.count - 1, section: 0)
|
||||||
|
messagesTableView.scrollToRow(at: indexPath, at: .top, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Blocking
|
// MARK: Blocking
|
||||||
|
|
|
@ -149,6 +149,8 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
||||||
static let scrollButtonFullVisibilityThreshold: CGFloat = 80
|
static let scrollButtonFullVisibilityThreshold: CGFloat = 80
|
||||||
/// The button will be invisible until the user has scrolled at least this amount from the bottom of the table view.
|
/// The button will be invisible until the user has scrolled at least this amount from the bottom of the table view.
|
||||||
static let scrollButtonNoVisibilityThreshold: CGFloat = 20
|
static let scrollButtonNoVisibilityThreshold: CGFloat = 20
|
||||||
|
/// Automatically scroll to the bottom of the conversation when sending a message if the scroll distance from the bottom is less than this number.
|
||||||
|
static let scrollToBottomMargin: CGFloat = 40
|
||||||
|
|
||||||
// MARK: Lifecycle
|
// MARK: Lifecycle
|
||||||
init(thread: TSThread, focusedMessageID: String? = nil) {
|
init(thread: TSThread, focusedMessageID: String? = nil) {
|
||||||
|
@ -222,13 +224,14 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
||||||
Storage.read { transaction in
|
Storage.read { transaction in
|
||||||
unreadCount = self.thread.unreadMessageCount(transaction: transaction)
|
unreadCount = self.thread.unreadMessageCount(transaction: transaction)
|
||||||
}
|
}
|
||||||
// When the unread message count is more than the number of a page of viewItems,
|
// When the unread message count is more than the number of view items of a page,
|
||||||
// the screen will scroll to bottom instead of the correct first unread message.
|
// the screen will scroll to the bottom instead of the first unread message.
|
||||||
// The unreadIndicatorIndex is calculated during loading the viewItems, it is
|
// unreadIndicatorIndex is calculated during loading of the viewItems, so it's
|
||||||
// supposed to be accurate.
|
// supposed to be accurate.
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
let unreadIndicatorIndex = self.viewModel.viewState.unreadIndicatorIndex?.intValue ?? (self.viewItems.count - self.unreadViewItems.count)
|
let firstUnreadMessageIndex = self.viewModel.viewState.unreadIndicatorIndex?.intValue
|
||||||
if unreadCount > 0, let viewItem = self.viewItems[ifValid: unreadIndicatorIndex], let interactionID = viewItem.interaction.uniqueId {
|
?? (self.viewItems.count - self.unreadViewItems.count)
|
||||||
|
if unreadCount > 0, let viewItem = self.viewItems[ifValid: firstUnreadMessageIndex], let interactionID = viewItem.interaction.uniqueId {
|
||||||
self.scrollToInteraction(with: interactionID, position: .top, isAnimated: false)
|
self.scrollToInteraction(with: interactionID, position: .top, isAnimated: false)
|
||||||
self.unreadCountView.alpha = self.scrollButton.alpha
|
self.unreadCountView.alpha = self.scrollButton.alpha
|
||||||
} else {
|
} else {
|
||||||
|
@ -350,11 +353,13 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
||||||
if update.viewItem?.interaction is TSOutgoingMessage {
|
if update.viewItem?.interaction is TSOutgoingMessage {
|
||||||
shouldScrollToBottom = true
|
shouldScrollToBottom = true
|
||||||
} else {
|
} else {
|
||||||
shouldScrollToBottom = (self.lastPageTop - self.messagesTableView.contentOffset.y) <= 0
|
let margin = (self.lastPageTop - self.messagesTableView.contentOffset.y)
|
||||||
|
shouldScrollToBottom = margin <= ConversationVC.scrollToBottomMargin
|
||||||
}
|
}
|
||||||
case .update:
|
case .update:
|
||||||
self.messagesTableView.reloadRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .fade)
|
self.messagesTableView.reloadRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .fade)
|
||||||
shouldScrollToBottom = (self.lastPageTop - self.messagesTableView.contentOffset.y) <= 0
|
let margin = (self.lastPageTop - self.messagesTableView.contentOffset.y)
|
||||||
|
shouldScrollToBottom = margin <= ConversationVC.scrollToBottomMargin
|
||||||
default: preconditionFailure()
|
default: preconditionFailure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,9 +147,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
BOOL areAllAttachmentsDownloaded = YES;
|
BOOL areAllAttachmentsDownloaded = YES;
|
||||||
for (NSString *attachmentId in self.attachmentIds) {
|
for (NSString *attachmentId in self.attachmentIds) {
|
||||||
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
|
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
|
||||||
// If the attachment download is failed, we can mark this message as read.
|
// If the attachment download failed, we can mark this message as read.
|
||||||
// Otherwise, this message will never be marked as read.
|
// Otherwise, this message will never be marked as read.
|
||||||
if ([attachment isKindOfClass:[TSAttachmentPointer class]] && ((TSAttachmentPointer *)attachment).state == TSAttachmentPointerStateFailed) {
|
if ([attachment isKindOfClass:[TSAttachmentPointer class]]
|
||||||
|
&& ((TSAttachmentPointer *)attachment).state == TSAttachmentPointerStateFailed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
areAllAttachmentsDownloaded = areAllAttachmentsDownloaded && attachment.isDownloaded;
|
areAllAttachmentsDownloaded = areAllAttachmentsDownloaded && attachment.isDownloaded;
|
||||||
|
|
Loading…
Reference in New Issue