MessageKit icon indicating copy to clipboard operation
MessageKit copied to clipboard

Fix scroll to last item to take section inset into account

Open hidoon opened this issue 1 year ago • 8 comments

What does this implement/fix? Explain your changes.

This correction addresses the bug (issue #1830) where scrollToLastItem(at:animated:) didn't perform as expected. Previously, it would scroll to the last item without considering the sectionInset, eliminating the gap between the last cell and inputBarAccessoryView.

Does this close any currently open issues?

Yes it does, (issue #1830 )

Where has this been tested?

Devices/Simulators:

  • IOS Simulator iPhone 15 Pro Max / iOS 17.0.1
  • Physical Device iPhone 13 / iOS 17.2.1 iOS Version:
  • IOS Simulator iPhone 15 Pro Max / iOS 17.0.1
  • Physical Device iPhone 13 / iOS 17.2.1 Swift Version:
  • Swift 5.9 MessageKit Version:
  • 4.2.0

hidoon avatar Feb 20 '24 18:02 hidoon

Hi @hidoon ! It looks like this issue did not fully still not solved. For example, in the Example code's Advanced VC, after entering the advanced vc, it is also not scrolling correctly to the bottom. Would you mind helping take a look what is wrong? Thank you so much! (I was using a similar approach in the example code for my own project, and have spent 10+ hrs already but still couldn't solve the issue myself 😢 )

Update - It seems like the issue happens when the custom input bar's height is larger than the default input bar's

Screenshot 2024-03-10 at 12 12 36 PM

luoshuaiqing avatar Mar 10 '24 19:03 luoshuaiqing

Another issue I found is: if I created a custom footer view for the messages collection view, scroll to bottom has a large and very noticeable padding at the bottom, and seems to be the exactly one footer cell's height.

luoshuaiqing avatar Mar 10 '24 19:03 luoshuaiqing

hi @luoshuaiqing, as far as I know, the messagesCollectionView is not related to inputBarAccessoryView, if you are talking about scrolling down. I don't know what to do to make pull request accepted and merged, but if you can, you can try to use my pull request to see if it fixes your issue. Btw, is the footer view you are talking about inputBarAccessoryView?

hidoon avatar Mar 10 '24 19:03 hidoon

hi @luoshuaiqing, as far as I know, the messagesCollectionView is not related to inputBarAccessoryView, if you are talking about scrolling down.

Oh I am not talking about scrolling down. I am talking about scrollToBottom() implementation in MessageKit is not correctly scrolling to bottom with custom input bar. (aka when I set messageInputBar = MyCustomView() and inputBarType = .custom(MyCustomView(). The fix in this PR didn't solve this issue unfortunately 😢

Btw, is the footer view you are talking about inputBarAccessoryView?

I am referring to messagesCollectionView.dequeueReusableFooterView(MyCustomFooterView.self, for: indexPath)

luoshuaiqing avatar Mar 10 '24 19:03 luoshuaiqing

@luoshuaiqing Oh, I see. I think the problem you face is the height of your custom view is not taken into account and messagesCollectionView stays behind your custom view. Idk if there is a data source or delegate function to specify the height of your custom view, but if there is not, maybe you can set a specific contentInset to messagesCollectionView. That's a hacky way but it may work.

hidoon avatar Mar 10 '24 19:03 hidoon

Thanks for the advice, but it looks like it didn't work after I do something like messagesCollectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: messageInputBar.frame.height, right: 0), and also I don't think there is a delegate method for accessory view size calculator

luoshuaiqing avatar Mar 10 '24 20:03 luoshuaiqing

hey luoshuaiqing and other who needs help, there is a function in InputBarAccessoryViewDelegate, which is delegate of messageInputBar, func inputBar(_ inputBar: InputBarAccessoryView, didChangeIntrinsicContentTo size: CGSize) gives new size.

hidoon avatar May 17 '24 14:05 hidoon

Is this ready to be merged given the conversation here?

Kaspik avatar Jul 11 '24 09:07 Kaspik