Skip to content

Instantly share code, notes, and snippets.

@Rspoon3
Last active August 20, 2020 23:36
Show Gist options
  • Select an option

  • Save Rspoon3/3ac80fe0e4153893f8aafbf33ea1b81f to your computer and use it in GitHub Desktop.

Select an option

Save Rspoon3/3ac80fe0e4153893f8aafbf33ea1b81f to your computer and use it in GitHub Desktop.
Scrolling stutters in a LazyVGrid on iOs 14, beta 5 due to the cell's context menu. If you comment it out, scrolling performance dramatically increases.
struct ContentView: View{
@State private var selection: Int? = nil
var body: some View{
NavigationView{
List{
Text("Does")
Text("Not")
Text("Matter")
Text("For")
Text("This")
Text("Example")
}.listStyle(SidebarListStyle())
ScrollView{
Text("In this example, scrolling stutters due to the cell's context menu. If you comment it out, scrolling performance dramatically increases. (SwiftUI, iOS 14, beta 5)")
.font(.title3)
LazyVGrid(columns: [GridItem(.adaptive(minimum: 140))], spacing: 30, content: {
ForEach(0..<199) { index in
NavigationLink(
destination: Text("\(index)"),
tag: index,
selection: $selection
) {
ContextMenuCell(index: index)
}.buttonStyle(PlainButtonStyle())
}
}).padding()
}.navigationTitle("Scrolling Stutter")
}
}
}
struct ContextMenuCell: View{
let index: Int
let colors = [Color.blue, .gray, .red, .green, .pink, .purple, .orange]
var body: some View{
colors.randomElement()!
.frame(height: 100)
.contextMenu{
ContextMenuButton(title: "Favorite") {}
ContextMenuButton(title: "Edit"){}
Menu{
ContextMenuButton(title: "File 1"){}
ContextMenuButton(title: "File 2"){}
} label: {
Text("Share")
Image(systemName: "flame")
.imageScale(.large)
}
Divider()
ContextMenuButton(title: "Delete") {}
}
}
}
struct ContextMenuButton: View {
let title: String
let action: () -> Void
var body: some View {
Button(action: {
self.action()
}, label: {
Label(title, systemImage: "photo")
.imageScale(.large)
})
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment