Sunday, December 15, 2024
HomeiOS Developmentios - iOS18 onTapGesture stopped working with Menu

ios – iOS18 onTapGesture stopped working with Menu


Problem:
After updating to Swift 6 and iOS 18, the Menu element’s interplay is just not behaving as anticipated. The onTapGesture and primaryAction do not work accurately to set off the specified motion when the consumer faucets on the menu.

Code Examples:

Utilizing onTapGesture with Menu (not working):

Menu {
    Button(motion: {}) {
        Label("Add to Studying Listing", systemImage: "eyeglasses")
    }
    Button(motion: {}) {
        Label("Add Bookmarks for All Tabs", systemImage: "ebook")
    }
    Button(motion: {}) {
        Label("Present All Bookmarks", systemImage: "books.vertical")
    }
} label: {
    Label("Add Bookmark", systemImage: "ebook")
} onTapGesture: {
    print("Print on faucet gesture")
}

Utilizing primaryAction (Menu not seems however motion is triggered on faucet):

Menu {
    Button(motion: {}) {
        Label("Add to Studying Listing", systemImage: "eyeglasses")
    }
    Button(motion: {}) {
        Label("Add Bookmarks for All Tabs", systemImage: "ebook")
    }
    Button(motion: {}) {
        Label("Present All Bookmarks", systemImage: "books.vertical")
    }
} label: {
    Label("Add Bookmark", systemImage: "ebook")
} primaryAction: {
    print("Main motion triggered")
}

Making an attempt to overlay a faucet space (no impact):

ZStack {
    Menu {
        Button(motion: {}) {
            Label("Add to Studying Listing", systemImage: "eyeglasses")
        }
        Button(motion: {}) {
            Label("Add Bookmarks for All Tabs", systemImage: "ebook")
        }
        Button(motion: {}) {
            Label("Present All Bookmarks", systemImage: "books.vertical")
        }
    } label: {
        Label("Add Bookmark", systemImage: "ebook")
    }
    Shade.clear
        .contentShape(Rectangle())
        .onTapGesture {
            print("Faucet gesture acknowledged")
        }
}

Please assist.

Tips on how to begin motion when consumer is clicking on menu?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments