ekazaev / ChatLayout

ChatLayout is an alternative solution to MessageKit. It uses custom UICollectionViewLayout to provide you full control over the presentation as well as all the tools available in UICollectionView. It supports dynamic cells and supplementary view sizes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iOS 15 multiple performBatchUpdates causes an animation problem

zendesk-benabu opened this issue · comments

On the last release of the Chatlayout this issues was address but not really fixed.
In-fact in the example all actions are added one after the other. The way we use the library involves several changes at the same time.

Step to reproduce:
Have two different actions in the same operation like: remove a message and add a new one.
To simulate that I have updated the sendMessage function in DefaultChatController in line 63 by adding the following code:
if !messages.isEmpty { messages.removeLast() }

So now when you send a message it will delete the last message in the conversation at same time.
The StagedChangeset is a collection that now have two operations which involve two performBatchUpdates
Sep-30-2021 14-22-31

I'm opening this pull request to suggest a solution and open the discussion to that.
#21

@zendesk-benabu Hi. Thank you for the issue. Yeah. It’s another tale as long as time. I hoped that apple will fix what they broke in the final release of ios 15 (how could they fecked up that math that worked fine since ios 6 i don’t understand), but it seems they are not going to. So it has to be handled on the client side. I’ll examine your PR a bit later and come back to you.

Hi @zendesk-benabu
Sorry for the delay. I was experimenting if I can somehow solve that on the collection layout side, but It seems that I wont be able to. It should be fixed by Apple. :(

Thank you @ekazaev. It's annoying, maybe we need to report the issue to Apple.
However it may be wanted in order to use the new iOS15 reconfigureItems api.

@zendesk-benabu No it should not be related. I mean, it can cause that bug when they were changing the collection view implementation. But it has nothing to do with it. They broke the math there. Seems that they are ignoring previous correction value until the latest one.

PS: I stopped even bother to report issues to apple as they clearly don't give a damn about bug reports. There are references in the code to the bug reports that hang there for ages.
5fes

@zendesk-benabu I can tell you that it is broken in IOS 15 not because of the collection view layout itself. They have changes something in UIScrollView. UICollectionView is doing everything correctly. I have contentOffset listener set. But at the end of performBatchUpdates UIScrollView forcefully updates contentOffset to the one it thinks correct, ignoring values that came from the UICollectionViewLayout.
In IOS 14

finalizeCollectionViewUpdates()1:2.0 - 46.0 - 2.0 - 0.0
invalidateLayout(with:)
CONTENT OFFSET OBSERVER: afterUpdate > |old: Optional((0.0, 4190.666666666665)) -> new: Optional((0.0, 4192.666666666667))| Optional((0.0, 4192.666666666667)) ***(0.0, -1.8189894035458565e-12)***

in IOS 15

finalizeCollectionViewUpdates()1:2.0 - 46.0 - 2.0 - 0.0
invalidateLayout(with:)
CONTENT OFFSET OBSERVER: afterUpdate > |old: Optional((0.0, 4374.666666666665)) -> new: Optional((0.0, 4376.666666666667))| Optional((0.0, 4376.666666666667)) ***(0.0, 0.0)***
CONTENT OFFSET OBSERVER: afterUpdate > |old: Optional((0.0, 4376.666666666667)) -> new: Optional((0.0, 4330.666666666667))| Optional((0.0, 4330.666666666667)) ***(0.0, 45.99999999999818)*** <- The extra call from UIScrollView

I assume teams do not talk to each other

Interesting ! No way for us to detect and ignore this updates ? Maybe by detecting it and force to the previous contentOffset
value?

I have the feeling that I may be able to tackle it somehow. Of course there is not way for us to ignore that settings, as it happen on the UIScrollView level. I have the feeling that they started to listen to content size changes within collection view layout during the animation. Of course it is just my assumpltion. But Ill try to compensate it mathematically.

@zendesk-benabu
I think I managed to avoid that strange extra call.
Can I ask you to play around with origin/feature/fix_ios15 branch. Especially it will be help-full in you real project.

Cool ! Thanks for the research ! I will try this soon and give you some feedbacks.

That's working very well. In my project I only update the override var collectionViewContentSize: CGSize { and remove the isIOS15orHigher condition. And this is working well below iOS15 too. Well done !

@zendesk-benabu Thank you for your help. That is basically it! Let me run it then on the devices I have and Ill release it.

@zendesk-benabu I tested on the available devices and simulators and it seems to be fine. I close the issue. Thank you again.

commented

You are really good, but MY App is developed in OC and I seem to have encountered this problem. When I was setting up the contentoffset of collectionView, the cell did not slide smoothly. I studied your code and found that I did not fully understand it. Can the author explain the principle of solving this problem? Thank you