Pārlūkot izejas kodu

fix scroll-down btn visibility when opening a chat with many unread messages (#1598)

* fix initial calculation of messageInputBars top y-coordinate, fixes visibility of the scroll-down button when searching or opening chats with many unread messages

* don't show scroll down button in empty chats
cyBerta 2 gadi atpakaļ
vecāks
revīzija
82a8b2ca9c
1 mainītis faili ar 7 papildinājumiem un 5 dzēšanām
  1. 7 5
      deltachat-ios/Chat/ChatViewController.swift

+ 7 - 5
deltachat-ios/Chat/ChatViewController.swift

@@ -774,7 +774,9 @@ class ChatViewController: UITableViewController {
     }
     }
 
 
     private func updateScrollDownButtonVisibility() {
     private func updateScrollDownButtonVisibility() {
-        messageInputBar.scrollDownButton.isHidden = isLastRowVisible(checkTopCellPostion: true, checkBottomCellPosition: true, allowPartialVisibility: true)
+        messageInputBar.scrollDownButton.isHidden = messageIds.isEmpty || isLastRowVisible(checkTopCellPostion: true,
+                                                                                           checkBottomCellPosition: true,
+                                                                                           allowPartialVisibility: true)
     }
     }
 
 
     private func configureContactRequestBar() {
     private func configureContactRequestBar() {
@@ -1042,17 +1044,17 @@ class ChatViewController: UITableViewController {
 
 
         let rectOfCellInTableView = tableView.rectForRow(at: lastIndexPath)
         let rectOfCellInTableView = tableView.rectForRow(at: lastIndexPath)
         // convert points to same coordination system
         // convert points to same coordination system
-        let inputBarTopInWindow = messageInputBar.convert(CGPoint(x: 0, y: messageInputBar.bounds.minY), to: window)
+        let inputBarTopInWindow = window.bounds.maxY - (messageInputBar.intrinsicContentSize.height + messageInputBar.keyboardHeight)
         var cellTopInWindow = tableView.convert(CGPoint(x: 0, y: rectOfCellInTableView.minY), to: window)
         var cellTopInWindow = tableView.convert(CGPoint(x: 0, y: rectOfCellInTableView.minY), to: window)
         cellTopInWindow.y = floor(cellTopInWindow.y)
         cellTopInWindow.y = floor(cellTopInWindow.y)
         var cellBottomInWindow = tableView.convert(CGPoint(x: 0, y: rectOfCellInTableView.maxY), to: window)
         var cellBottomInWindow = tableView.convert(CGPoint(x: 0, y: rectOfCellInTableView.maxY), to: window)
         cellBottomInWindow.y = floor(cellBottomInWindow.y)
         cellBottomInWindow.y = floor(cellBottomInWindow.y)
         let tableViewTopInWindow = tableView.convert(CGPoint(x: 0, y: tableView.bounds.minY), to: window)
         let tableViewTopInWindow = tableView.convert(CGPoint(x: 0, y: tableView.bounds.minY), to: window)
         // check if top and bottom of the message are within the visible area
         // check if top and bottom of the message are within the visible area
-        let isTopVisible = cellTopInWindow.y < inputBarTopInWindow.y && cellTopInWindow.y >= tableViewTopInWindow.y
-        let isBottomVisible = cellBottomInWindow.y <= inputBarTopInWindow.y && cellBottomInWindow.y >= tableViewTopInWindow.y
+        let isTopVisible = cellTopInWindow.y < inputBarTopInWindow && cellTopInWindow.y >= tableViewTopInWindow.y
+        let isBottomVisible = cellBottomInWindow.y <= inputBarTopInWindow && cellBottomInWindow.y >= tableViewTopInWindow.y
         // check if the message is visible, but top and bottom of cell exceed visible area
         // check if the message is visible, but top and bottom of cell exceed visible area
-        let messageExceedsScreen = cellTopInWindow.y < tableViewTopInWindow.y && cellBottomInWindow.y > inputBarTopInWindow.y
+        let messageExceedsScreen = cellTopInWindow.y < tableViewTopInWindow.y && cellBottomInWindow.y > inputBarTopInWindow
         if checkTopCellPostion && checkBottomCellPosition {
         if checkTopCellPostion && checkBottomCellPosition {
             return allowPartialVisibility ?
             return allowPartialVisibility ?
             isTopVisible || isBottomVisible || messageExceedsScreen :
             isTopVisible || isBottomVisible || messageExceedsScreen :