После обновления до Swift 6 и iOS 18 взаимодействие компонента меню работает не так, как ожидалось. onTapGesture и PrimaryAction работают неправильно, вызывая желаемое действие, когда пользователь нажимает на меню.
Примеры кода:
Использование onTapGesture с Меню (не работает):
Код: Выделить всё
Menu {
Button(action: {}) {
Label("Add to Reading List", systemImage: "eyeglasses")
}
Button(action: {}) {
Label("Add Bookmarks for All Tabs", systemImage: "book")
}
Button(action: {}) {
Label("Show All Bookmarks", systemImage: "books.vertical")
}
} label: {
Label("Add Bookmark", systemImage: "book")
} onTapGesture: {
print("Print on tap gesture")
}
Код: Выделить всё
Menu {
Button(action: {}) {
Label("Add to Reading List", systemImage: "eyeglasses")
}
Button(action: {}) {
Label("Add Bookmarks for All Tabs", systemImage: "book")
}
Button(action: {}) {
Label("Show All Bookmarks", systemImage: "books.vertical")
}
} label: {
Label("Add Bookmark", systemImage: "book")
} primaryAction: {
print("Primary action triggered")
}
Код: Выделить всё
ZStack {
Menu {
Button(action: {}) {
Label("Add to Reading List", systemImage: "eyeglasses")
}
Button(action: {}) {
Label("Add Bookmarks for All Tabs", systemImage: "book")
}
Button(action: {}) {
Label("Show All Bookmarks", systemImage: "books.vertical")
}
} label: {
Label("Add Bookmark", systemImage: "book")
}
Color.clear
.contentShape(Rectangle())
.onTapGesture {
print("Tap gesture recognized")
}
}
Как начать действие, когда пользователь нажимает на меню?
Подробнее здесь: https://stackoverflow.com/questions/790 ... -with-menu
Мобильная версия