danielsaidi / ScrollKit

ScrollKit is a SwiftUI SDK that adds powerful scroll features, like offset tracking and a header view that stretches & transforms as you pull down, and sticks to the top when you scroll.
MIT License
668 stars 24 forks source link

iOS 17 bug #7

Closed ALexanderLonsky closed 11 months ago

ALexanderLonsky commented 1 year ago

Hello, It seems that iOS 17 has broken the scale logic: When you swipe down, the header doesn't scale up as expected. Instead, there's a noticeable twitching as it just jumps back and forth. I can reproduce the issue on the simulator and a device running the latest iOS 17 beta.

danielsaidi commented 12 months ago

Hi @ALexanderLonsky

Thanks for letting me know. I haven't looked at it yet, but I have seen strange things in iOS 17 😬

Any idea what's causing this?

morluna commented 11 months ago

Hi @danielsaidi hope you're doing well!

@ALexanderLonsky I actually ran into this as well for iOS 17. I had a complex scroll view with various elements and nested VStacks and I could see the screen jitter when scrolling.

Luckily my preview wasn't broken, so it was indicating that something inside my scroll view was probably being treated differently. Turns out that nesting VStacks with ForEach inside is what's causing this issue. Not totally sure why, but maybe SwiftUI is trying to optimize some performance if you don't have lazy stacks.

Basically switching any VStacks like this into `LazyVStacks does the trick

ScrollViewWithStickyHeader(
            header: header,
            headerHeight: 250,
            onScroll: handleOffset
) {
    ....
    VStack { /// <--- switch to LazyVStack
        ForEach(...){}
    }
    ....
 }
morluna commented 11 months ago

Sad.... never mind to my suggestion above ^. It worked for simulators, but physical devices are still affected 😔

danielsaidi commented 11 months ago

Hey @morluna - long time no see! Hope you're well too 😀

I've had a few strange iOS 17 animation glitches, and seen others have them too.

I haven't had time to look at this yet, but in this case, perhaps the size is messed up by the lazy stack? It would be a real shame if it couldn't be used with lazy stacks and lists anymore.

morluna commented 11 months ago

Yeah so actually I was able to fix it for the most part by doing two things:

  1. Swap LazyVStacks to VStacks
  2. Make nested subviews their own structs

I noted how it's not always optimal to move from lazy to regular stacks but it worked for us because we aren't displaying that many items to begin with.

I talked more about it on this forum of a user running into this issue with the offset tracking not working properly: https://developer.apple.com/forums/thread/736813?login=true&page=1#766588022

danielsaidi commented 11 months ago

@ALexanderLonsky @morluna I have run the ScrollKit demo app in Xcode 15, on both the iPhone 15 Pro simulator and on a real device, and it works perfectly fine there.

Here's a video from the demo app running on a real device:

https://github.com/danielsaidi/ScrollKit/assets/429927/728605f7-b01c-4489-91dc-51c022017567

Perhaps it has to do with that the demo's LazyVStack has items with a single height?

ALexanderLonsky commented 11 months ago

@danielsaidi, thank you for your answers. I'm sorry I missed them.

Indeed, your demo works well, so I looked at my implementation, and in my case, wrapping LazyVStack in ScrollView resolved the issue.

(CC @morluna ^^)

Thanks!

danielsaidi commented 11 months ago

Cool, thanks for letting me know and happy to hear that it works now 🥂