Hi,
in Xcode 12.0.1
I am using .contextMenu to show options to users. After moving from List to LazyVStack the preview of the the view changes to look strange.
The preview now is not full view but split-up. How can we control the view that .contextMenu show?
Also it seems .contextMenu deprecated in iOS 14+ - what is the alternative to .contextMenu?
I have this test code - try to show the context menu for the first row and see the preview spilt up with row and the strength Mild.
import SwiftUI
struct TestView: View {
@State var value: String = ""
var strengths = ["Mild", "Medium", "Mature"]
@State private var selectedStrength = 0
var body: some View {
VStack {
VStack {
Text("Header").font(.headline).padding(.top)
}
Divider()
VStack {
TestHeaderView().padding(.horizontal)
Divider()
ScrollView {
LazyVStack(alignment: .leading) {
ForEach(0 ..< strengths.count) {
TestRowView(event: self.strengths[$0]).contextMenu {
Text("Context")
}
}
}.padding(.horizontal)
}
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
struct TestRowView : View {
let event: String
var gridItemLayout = [GridItem(.flexible(maximum: 20)), GridItem(.flexible()), GridItem(.flexible())]
var body: some View {
VStack {
LazyVGrid(columns: gridItemLayout, alignment: .leading) {
Image(systemName: "doc.plaintext").foregroundColor(.blue)
Text("Row")
Text(event)
}
Divider()
}
}
}
struct TestHeaderView : View {
var gridItemLayout = [GridItem(.flexible(maximum: 20)), GridItem(.flexible()), GridItem(.flexible())]
var body: some View {
LazyVGrid(columns: gridItemLayout, alignment: .leading) {
Text("").foregroundColor(.blue)
Text("Description1").foregroundColor(.blue)
Text("Description2").foregroundColor(.blue)
}
}
}
in Xcode 12.0.1
I am using .contextMenu to show options to users. After moving from List to LazyVStack the preview of the the view changes to look strange.
The preview now is not full view but split-up. How can we control the view that .contextMenu show?
Also it seems .contextMenu deprecated in iOS 14+ - what is the alternative to .contextMenu?
I have this test code - try to show the context menu for the first row and see the preview spilt up with row and the strength Mild.
import SwiftUI
struct TestView: View {
@State var value: String = ""
var strengths = ["Mild", "Medium", "Mature"]
@State private var selectedStrength = 0
var body: some View {
VStack {
VStack {
Text("Header").font(.headline).padding(.top)
}
Divider()
VStack {
TestHeaderView().padding(.horizontal)
Divider()
ScrollView {
LazyVStack(alignment: .leading) {
ForEach(0 ..< strengths.count) {
TestRowView(event: self.strengths[$0]).contextMenu {
Text("Context")
}
}
}.padding(.horizontal)
}
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
struct TestRowView : View {
let event: String
var gridItemLayout = [GridItem(.flexible(maximum: 20)), GridItem(.flexible()), GridItem(.flexible())]
var body: some View {
VStack {
LazyVGrid(columns: gridItemLayout, alignment: .leading) {
Image(systemName: "doc.plaintext").foregroundColor(.blue)
Text("Row")
Text(event)
}
Divider()
}
}
}
struct TestHeaderView : View {
var gridItemLayout = [GridItem(.flexible(maximum: 20)), GridItem(.flexible()), GridItem(.flexible())]
var body: some View {
LazyVGrid(columns: gridItemLayout, alignment: .leading) {
Text("").foregroundColor(.blue)
Text("Description1").foregroundColor(.blue)
Text("Description2").foregroundColor(.blue)
}
}
}