Kaynağa Gözat

Update grid sample

onevcat 5 yıl önce
ebeveyn
işleme
1983a38df1

+ 16 - 2
Demo/Demo/Kingfisher-Demo/SwiftUIViews/GridDemo.swift

@@ -29,14 +29,28 @@ import SwiftUI
 @available(iOS 14.0, *)
 struct GridDemo: View {
 
-    let columns = [
+    @State var columns = [
         GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())
     ]
     var body: some View {
         ScrollView {
             LazyVGrid(columns: columns) {
                 ForEach(1..<700) { i in
-                    ImageCell(index: i)
+                    ImageCell(index: i).frame(height: columns.count == 1 ? 300 : 150)
+                }
+            }
+        }.navigationBarTitle(Text("Grid"))
+        .toolbar {
+            ToolbarItem(placement: .navigationBarTrailing) {
+                Button(action: {
+
+                    withAnimation(Animation.easeInOut(duration: 0.25)) {
+                        self.columns = Array(repeating: .init(.flexible()), count: self.columns.count % 4 + 1)
+                    }
+                }) {
+                    Image(systemName: "square.grid.2x2")
+                        .font(.title)
+                        .foregroundColor(.primary)
                 }
             }
         }