fermoya / SwiftUIPager

Native Pager in SwiftUI
MIT License
1.25k stars 165 forks source link

[BUG] Preview doesn't work as expected #76

Closed orkenstein closed 3 years ago

orkenstein commented 3 years ago

Describe the bug Canvas preview in Xcode does not render the pager.

To Reproduce

import SwiftUI
import SwiftUIPager

struct WelcomeView: View {
  @State var page: Int = 0
  var items = Array(0..<10)

  var body: some View {
    Pager(page: $page,
          data: items,
          id: \.self,
          content: { index in
            // create a page based on the data passed
            Text("Page: \(index)").background(Color.yellow).frame(width: 100, height: 100)
    }).background(Color.green)
  }
}

struct WelcomeView_Previews: PreviewProvider {
  static var previews: some View {
    WelcomeView()
  }
}

Expected behavior Expected to have rendered view in preview.

Screenshots / Videos

Screen Shot 2020-07-21 at 16 42 36

Environment:

fermoya commented 3 years ago

Hi @orkenstein , I’m well aware of this issue. It’s due to the dependence of Pager on SizeModifier. It makes it not run the Preview but makes the code more readable and maintainable.

I’m not going to prioritize this as I there are other issues that are more urgent. Nonetheless, I’ll be taking a look at this promptly and see if there’s anything I could improve there to make it work.

Thanks for your feedback

UPDATE: I’ve confirmed a way to fix this and was able to see Pager in the preview by using a hack. I’ll be working on a neat implementation shortly

fermoya commented 3 years ago

Fixed in version 1.9.0. See preview example here.

Don't forget to star the repository if you like it 😊.

Screenshot 2020-07-24 at 18 13 52
orkenstein commented 3 years ago

Yes, works just fine, thanks a lot! 🔥