Q-Mobile / QGrid

🎛 QGrid: The missing SwiftUI collection view.
MIT License
1.64k stars 104 forks source link

When opening app in landscape, wrong number of columns displayed #18

Open simibac opened 4 years ago

simibac commented 4 years ago

The wrong number of columns are displayed, when opening the app directly in landscape. The initial device orientation is not detected.

karolkulesza commented 4 years ago

Cannot reproduce. Are you able to provide more details? Are you using the test app delivered within this repo? If not, please provide sample code. Which device/simulator are you testing on? (with exact iOS version).

simibac commented 4 years ago

The problem can be reproduced as follows:

  1. Use QGrid within a NavigationLink
struct DataPoint: Identifiable{
    var id = UUID()
    var name:String
}

struct ContentView: View {
    var data:Array<DataPoint> = [DataPoint(name: "A"), DataPoint(name: "B"), DataPoint(name: "C"), DataPoint(name: "D"), DataPoint(name: "E"), DataPoint(name: "F"), DataPoint(name: "G"), DataPoint(name: "H"), DataPoint(name: "J"), DataPoint(name: "K"), DataPoint(name: "L"), DataPoint(name: "M")]

    var body: some View {
        NavigationView{
            NavigationLink(destination:
                QGrid(data,
                  columns: 1,
                  columnsInLandscape: 4,
                  content: { data in
                    VStack{
                        Text(data.name)
                    }
                })
            ){
                Text("navigate to QGrid")
            }
        }
    }
}
  1. Start simulator and rotate it to landscape.

  2. Build and run application.

  3. Navigate to QGrid.

Screenshot 2019-11-11 at 12 46 29 Screenshot 2019-11-11 at 12 46 35

:warning: This shows the wrong number of columns.

  1. Rotate device to portrait and back to landscape. Screenshot 2019-11-11 at 12 48 10

:heavy_check_mark: This shows the correct amount of columns.