Return Value 戻り値
A modified representation of this view. このビューの修正された表現。
Availability 有効性
Technology
func focusedSceneValue<T>(_ keyPath: WritableKeyPath
<FocusedValues
, T?>, _ value: T) -> some View
A modified representation of this view. このビューの修正された表現。
keyPath
The key path to associate value
with when adding it to the existing table of published focus values.
value
The focus value to publish.
Use this method instead of focused
for values that must be visible regardless of where focus is located in the active scene. For example, if an app needs a command for moving focus to a particular text field in the sidebar, it could use this modifier to publish a button action that’s visible to command views as long as the scene is active, and regardless of where focus happens to be in it.
struct Sidebar: View {
var isFiltering: Bool
var body: some View {
VStack {
TextField(...)
.focused(when: $isFiltering)
.focusedSceneValue(\.filterAction) {
isFiltering = true
}
}
}
}
struct NavigationCommands: Commands {
var filterAction (\.filterAction)
var body: some Commands {
CommandMenu("Navigate") {
Button("Filter in Sidebar") {
filterAction?()
}
}
.disabled(filterAction == nil)
}
}
struct FilterActionKey: FocusedValuesKey {
typealias Value = () -> Void
}
extension FocusedValues {
var filterAction: (() -> Void)? {
get { self[FilterActionKey.self] }
set { self[FilterActionKey.self] = newValue }
}
}