nachonavarro / Pages

📖 A lightweight, paging view solution for SwiftUI
MIT License
586 stars 55 forks source link

Cannot add images #12

Closed iambenmitchell closed 4 years ago

iambenmitchell commented 4 years ago

Hello, I am trying to make a TikTok style UI.

I have tried this:

struct ContentView: View {
     @State var index: Int = 0
   var body: some View {
            Pages(currentPage: $index, navigationOrientation: .vertical) {
                Image("ModelX")
            }
        }
    }

However I get this error:Cannot convert value of type 'Image' to closure result type '[AnyView]'

I have also tried doing this:

struct ContentView: View {
     @State var index: Int = 0
   var body: some View {
            Pages(currentPage: $index, navigationOrientation: .vertical) {
                NewsView()
            }
        }
    }

struct NewsView: View{
    var body: some View {
        Image("modelX")
    }

}

However I get the same error but lightly different: Cannot convert value of type 'NewsView' to closure result type '[AnyView]'

Anyhelp is appreciated, I am not a noob but I am new to swiftUI

iambenmitchell commented 4 years ago

Solved: I am an idiot, I got this error before I added a second item.

You must have at least two items ie

Image("")
Image("")

I got thrown off because I usually stop as soon as I see an error

nachonavarro commented 4 years ago

No worries :)

As you can read in the docs, the Pages view needs more than one page. Otherwise the compiler treats what's inside Pages as a closure.

iambenmitchell commented 4 years ago

No worries :)

As you can read in the docs, the Pages view needs more than one page. Otherwise the compiler treats what's inside Pages as a closure.

I am having another issue now where images don’t behave correctly: https://twitter.com/a_mrbenmitchell/status/1251582028606246914?s=21

iambenmitchell commented 4 years ago

13