Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't load dynamic data inside PaginationView #50

Closed
sabina1997 opened this issue Apr 16, 2020 · 9 comments
Closed

Can't load dynamic data inside PaginationView #50

sabina1997 opened this issue Apr 16, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@sabina1997
Copy link

sabina1997 commented Apr 16, 2020

I have to display some data from api. This is the code:

PaginationView(axis: .horizontal) {

                ForEach(self.banners, id: \.id) { item in
               
URLImage(URL(string:"exampleurl")!)
                    { proxy in
                        proxy.image
                            .resizable()
                    }.frame(width: UIScreen.main.bounds.width - 120, height: 200).aspectRatio(contentMode: .fit)
                        .cornerRadius(15)

                }
                
            }.onAppear(perform: loadData)

Everything I put inside foreach, even if I put static data it says Cannot convert value of type 'ForEach<[Banner], Int, some View>' to closure result type 'Array'.
How can I load data with foreach inside PaginationView?

@vmanot
Copy link
Member

vmanot commented Apr 16, 2020

@sabina1997 I just introduced an initializer to support this. Could you check and confirm whether it fits your need?

@vmanot
Copy link
Member

vmanot commented Apr 16, 2020

On a more interesting note - true ForEach support is in the works. Right now, PaginationView is inefficient in that it requires precomputed views - I'm changing that to support fully dynamic, lazy loading.

@sabina1997
Copy link
Author

@sabina1997 I just introduced an initializer to support this. Could you check and confirm whether it fits your need?

Show an example please

@vmanot
Copy link
Member

vmanot commented Apr 17, 2020

@sabina1997 your main example should work?

@sabina1997
Copy link
Author

No it doesnt work

@sabina1997
Copy link
Author

Screenshot 2020-04-17 at 6 51 09 PM

@vmanot
Copy link
Member

vmanot commented Apr 17, 2020

The following code works for me, I'm not sure what I'm missing here:

Screen Shot 2020-04-18 at 2 54 21 AM

struct ContentView: View {
    var body: some View {
        PaginationView {
            ForEach([1, 2, 3], id: \.hashValue) {
                Text(String($0))
            }
        }
    }
}

Which version of Xcode are you using? Maybe your SPM package resolution is out of date? You should essentially see the following init in the generated interface for the SwiftUIX module:

Screen Shot 2020-04-18 at 2 55 41 AM

@vmanot vmanot added the enhancement New feature or request label Apr 18, 2020
@sabina1997
Copy link
Author

I just updated xcode to check if that was the problem. Now Im getting two errors

Screenshot 2020-04-18 at 9 10 23 PM

@sabina1997
Copy link
Author

@vmanot I found the problem, when I get the package with branch master, I didnt get the updates, I tried with commit and now its working , thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants