Delegate is overridden on `register(scrollView:)`
Current behaviour
When passing a UIScrollView to the SimultaneouslyScrollViewHandler using the register(scrollView:) method, a potentially already set delegate will be overridden.
Expected behaviour
An already set delegate should not be overridden when registering a UIScrollView.
Hi, is any idea to fix this issue? Thanks!
One approach could be to store the delegate (if any) inside the SimultaneouslyScrollViewHandler and delegate all delegate calls to it.
There's actually a secondary problem with that: If you call register(scrollView:) twice (with a different scroll view handler), the synchronisation done by the first handler will stop working. Obviously because the delegate is overwritten.
This can be dealt with, but someone else setting a delegate can always be a problem. I's possible to deal with a delegate that's already set, but there's not much* that can be done about someone else overwriting the delegate later and breaking the scroll view synchronisation.
* technically it's possible to swizzle the delegate setter on UIScrollView.
I made another discovery: SwiftUI already sets a delegate on UIScrollView called SwiftUI.ScrollViewHelper. I didn't find any public documentation on what that does, but just overwriting it probably breaks something.
SwiftUI already sets a delegate on UIScrollView called SwiftUI.ScrollViewHelper.
that's interesting 👀. wasn't aware of this 🤔 maybe it's time to keep the original delegate and proxy through to it.
I've implemented a solution; maybe I have time to create a pull request later in the evening. It doesn't help if someone else sets the delegate later on though, but in my brief testing that hasn't happened.
that would be awesome 🙌
Took me a day longer, but I've submitted my pull request.
By the way, the reason why I started to investigate is because of my use case: I basically have a layout like in a spreadsheet application. A scrollview for the row headers that only scroll vertically, a scrollview for the column headers that only scroll horizontally, and a grid of cells that scroll both ways. The grid of cells needs to be synced to two other scroll views using two different handlers. That didn't work prior to adding the multicast delegate stuff.