Hi,
In iPadOS can we use a .focusedSceneValue
, defined from a command/Button inside a Scene, from inside the .command
modifier attached to the scene?
Like this:
@main struct test_focusedSceneValueApp: App { var body: some Scene { WindowGroup { ContentView() } .commands { NavigationCommands() } } } struct NavigationCommands: Commands { @FocusedValue(\.filterAction) var filterAction var body: some Commands { CommandMenu("Navigate") { Button("Test focusedSceneValue") { filterAction?() } .keyboardShortcut("5") } } } struct ContentView: View { @FocusState var isFiltering: Bool @State private var focusField: String = "***** field *****" var body: some View { TextField("***** focus", text: $focusField) .focused($isFiltering) .focusedSceneValue(\.filterAction) { print("test successful") isFiltering = true } }
This code is almost the same from the sample code from the documentation, however I can only retrieved nil values from the @FocusedValue
and not the defined value.
Thanks.