fermoya / SwiftUIPager

Native Pager in SwiftUI
MIT License
1.27k stars 168 forks source link

[BUG] ios13 and 2.3.3+ #283

Closed kristohear closed 2 years ago

kristohear commented 2 years ago

Describe the bug Scrolling always resets to the position where the user tapped/started the scroll

To Reproduce Install the example project and run it. I replaced my custom page scroll with example one, just to be sure it is a swiftuipager issue.

Expected behavior Scroll should work as in ios14, and ios15 devices and in 2.3.3 and 2.4.0 versions. It should not be stuck on one page.

Screenshots / Videos

https://user-images.githubusercontent.com/74199206/170687011-b3385dc5-72f1-4f07-8e6b-f67a6139cbdd.mp4

Environment:

fermoya commented 2 years ago

@kristohear can you share this code or some pseudo-code with me? Where is your @ObservedObject var page living? It looks as if your whole screen is being recreated when this property updates which is not what you want. It works in iOS 14+ because of StateObject but state management is somewhat more delicate in iOS 13.

This coups be easily solved I think if you had something like this:

@ObservedObject var page: Page = .first

// inside `MyPagerContainer`
var body: some View {
  ...
  MyView(page: page)
  ...
}

And then:

var body: some View {
  VStack {
    MyPagerContainer()
    MyPagerContainer()
  }
}

This way, Pager changes the page but MyPagerContainer doesn't get recreated (and page doesn't reset) because its a different view that doesn't depend on page