Search code examples
swiftlistswiftuiscrollcontextmenu

SwiftUI Context Menu Has Extra Scrollable Space For No Reason


I have a list of items, each with a .contextMenu. The menu works, but for some reason it is scrollable and has extra empty space above all buttons.

My simplified code. This view is a list item in a scrollable list:

GeometryReader { geometry in
        ZStack(alignment: .leading) {
            //custom view here
        }
    }
    .contextMenu {
        Button(action: {
            //action here
        }, label: {
            Label("Edit", systemImage: "square.and.pencil")
        })
        Button(role: .destructive, action: {
            //action here
        }, label: {
            Label("Delete", systemImage: "trash")
        })
    }

What am I doing wrong?


Solution

  • I have UIScrollView.appearance().contentInset = UIEdgeInsets(top: 200, left: 0, bottom: 0, right: 0) for an unrelated ScrollView, but turns out that this affects the contextMenu as well. I assuming context menu is a scrollview under the hood.