Posts

Post not yet marked as solved
0 Replies
2.2k Views
I found an unexpected behavior with the pinnedViews (header, footer) in LazyVStack. When you have a LazyVStack with buttons and scroll through it, you can sometimes click the button even it's behind a pinned view. When you have a VStack with a View and a LazyVStack and scroll though the list, sometimes the buttons will trigger even through the top view above the LazyVStack. Example Code -> Scroll the List and click e.g. in the Top Area or Header. Sometimes the button is triggered. Especially if the list scrolls slow and sometimes even without scrolling. struct Test3: View { &#9;&#9;var headerView: some View { &#9;&#9;&#9;&#9;ZStack{ &#9;&#9;&#9;&#9;&#9;&#9;Rectangle() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.opacity(0.8) &#9;&#9;&#9;&#9;&#9;&#9;Text("Header") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.orange) &#9;&#9;&#9;&#9;}.frame(height: 50) &#9;&#9;} &#9;&#9; &#9;&#9;var footerView: some View { &#9;&#9;&#9;&#9;ZStack{ &#9;&#9;&#9;&#9;&#9;&#9;Rectangle() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.opacity(0.8) &#9;&#9;&#9;&#9;&#9;&#9;Text("Footer") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.orange) &#9;&#9;&#9;&#9;}.frame(height: 50) &#9;&#9;} &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack{ &#9;&#9;&#9;&#9;&#9;&#9;ZStack{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Rectangle() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.opacity(0.9) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Top Area") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.orange) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;.frame(height: 40) &#9;&#9;&#9;&#9;&#9;&#9;ScrollView { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;LazyVStack(alignment: .center, spacing: 10, pinnedViews: [.sectionHeaders, .sectionFooters], content: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(1...4, id: \.self) { section in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section(header: headerView, footer: footerView) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach(1..<121) { item in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("action") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;label: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ZStack{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Rectangle() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(height: 34) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Section: \(section), Item: \(item)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.orange) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.padding(.horizontal, 20) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} }
Posted
by HeGer.
Last updated
.
Post marked as solved
1 Replies
4.6k Views
My app crashes on iPhone/iPad Simulator when I'm using 2 ForEach in a LazyVStack. In the Canvas is works perfectly fine. Error message is: 'Fatal error: each layout item may only occur once' Minimum example: struct ContentView: View {     var body: some View {         ScrollView {             LazyVStack{                 ForEach(0...2, id: \.self) { _ in                     Section {                         ForEach(0..<2, id: \.self) { idx in                             Text("Section Cell \(idx)")                         }                     }                 }             }         }     } } If you change the LazyVStack with Vstack it work and if you delete one of the ForEach it work also on the simulator.
Posted
by HeGer.
Last updated
.
Post not yet marked as solved
1 Replies
1.2k Views
I think it's is really unfortunate that you can't set the first responder in SwiftUI, as an apple engineer stated in this forum. Will it be possible to add an own toolbar, custom buttons or similar above the keyboard? Will it be possible to automatically shrink the current view when an keyboard enters the display (like in a VStack). I really wish be could do more with the keyboard, since it is an essential element of the user experience.
Posted
by HeGer.
Last updated
.