FocusedValue / FocusedBinding не работает на iPadIOS

Программируем под IOS
Ответить
Anonymous
 FocusedValue / FocusedBinding не работает на iPad

Сообщение Anonymous »

Aim
  • To use a keyboard shortcut on a Multiplatform app (iOS and macOS)
  • When keyboard shortcut is tapped, the price needs to be printed
Problem

The same code doesn't Работайте над iPad, но работает над macOS < /li>
< /ul>
Вопрос: < /h3>

Почему не работает? 11.6 (20G165) < /li>
Версия 13.0 (13A233) < /li>
< /ul>
code < /h3>
@main
struct TestApp: App {
@State private var price = 0

var body: some Scene {
WindowGroup {
ContentView(price: $price)
.focusedValue(\.price, $price)
}
.commands {
PriceCommands()
}
}
}

struct ContentView: View {

@Binding var price: Int

var body: some View {
IncreasePriceButton(price: $price)
}
}

struct IncreasePriceButton: View {

@Binding var price: Int

var body: some View {
Button("Increase Price") {
price += 1
print("price = \(price)")
}
}
}

struct PriceCommandButton: View {

@FocusedBinding(\.price) var price

var body: some View {
Button("Print Price") {
print("price = \(price)")
}
}
}

struct PriceCommands: Commands {
var body: some Commands {
CommandMenu("Custom") {
PriceCommandButton()
.keyboardShortcut(KeyboardShortcut("C", modifiers: [.command, .shift]))
}
}
}

struct FocusedPriceKey: FocusedValueKey {
typealias Value = Binding
}

extension FocusedValues {
var price: FocusedPriceKey.Value? {
get { self[FocusedPriceKey.self] }
set { self[FocusedPriceKey.self] = newValue }
}
}


Подробнее здесь: https://stackoverflow.com/questions/695 ... ng-on-ipad
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»