FindContext
The status of the find navigator for views which support text editing.
Declaration
type FindContext = { readonly isPresented: Binding<boolean> | null; readonly supportsReplace: boolean; };struct FindContextProperties
isPresented*Binding<boolean> | nullsupportsReplace*boolean
Overview
Views which support text editing can use this information to implement a a find navigator that is controlled using the modifiers used for controlling the find navigator throughout the rest of SwiftUI.
For example, the following shows a minimal find navigator implementation
driven by the find context which falls back to local state if no
isPresented binding is provided:
struct FindNavigatorDrivenTextInput: View {
@State private var text: String = ""
@State private var showFindNavigator = false
@Environment(\.findContext) var findContext
var body: some View {
MyTextInputView(text: $text)
.overlay(alignment: .topTrailing) {
if let context = findContext &&
context.isPresented?.wrappedValue ?? showFindNavigator
{
HStack {
FindInputView(text: text)
if context.allowedOperations == .findAndReplace {
ReplaceInputView(text: $text)
}
Button("Close") {
context.isPresented?.wrappedValue = false
showFindNavigator = false
}
}
} else {
Button("Show Find Navigator") {
context.isPresented?.wrappedValue = true
showFindNavigator = true
}
}
}
}
}From Apple’s SwiftUI documentation. Code samples there are Swift.
See also
More in Text and symbols.
- DisabledTextSelectabilityA selectability type that disables text selection by the person using your app.
- EnabledTextSelectabilityA selectability type that enables text selection by the person using your app.
- FixedTextVariantThe default text variant preference that chooses the largest available variant.
- FontAn environment-dependent font.
- FontChainFont with chained calls: SwiftUI.Font.bold(...).
- FontContextInformation used to resolve a font.
- FontDesignA design to use for fonts.
- FontLeadingA line spacing adjustment that you can apply to a font.
- FontWeightA weight to use for fonts.
- FontWidthA width to use for fonts that have multiple widths.
- SubmitLabelA semantic label describing the label of submission within a view hierarchy.
- SubmitTriggersA type that defines various triggers that result in the firing of a submission action.