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 {
		var headerView: some View {
				ZStack{
						Rectangle()
								.opacity(0.8)
						Text("Header")
								.foregroundColor(.orange)
				}.frame(height: 50)
		}
		
		var footerView: some View {
				ZStack{
						Rectangle()
								.opacity(0.8)
						Text("Footer")
								.foregroundColor(.orange)
				}.frame(height: 50)
		}
		
		var body: some View {
				VStack{
						ZStack{
								Rectangle()
										.opacity(0.9)
								Text("Top Area")
										.foregroundColor(.orange)
						}
						.frame(height: 40)
						ScrollView {
								LazyVStack(alignment: .center, spacing: 10, pinnedViews: [.sectionHeaders, .sectionFooters], content: {
										ForEach(1...4, id: \.self) { section in
												Section(header: headerView, footer: footerView) {
														ForEach(1..<121) { item in
																Button(action: {
																		print("action")
																},
																label: {
																		ZStack{
																				Rectangle()
																						.frame(height: 34)
																				Text("Section: \(section), Item: \(item)")
																						.foregroundColor(.orange)
																		}
																		.padding(.horizontal, 20)
																})
														}
												}
										}
								})
						}
				}
		}
}
Post
Replies
Boosts
Views
Activity
Will the menus come to SwiftUI for iPhone?
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.
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.