Declaration
import { PasteButton } from 'swiftui-react-native';nonisolated struct PasteButtonInitializers
One SwiftUI initializer backs <PasteButton>.
<PasteButton
payloadType: SwiftUnsupported<'T.Type'>
onPaste: (arg0: any[]) => void
/>nonisolated init<T>(
payloadType: T.Type,
onPaste: @escaping ([T]) -> Void
)
where T : TransferablepayloadType*SwiftUnsupported<'T.Type'>The type that you want to paste via the
PasteButton.onPaste*(arg0: any[]) => voidThe handler to call on trigger of the button with at least one item of the specified
Transferabletype from the pasteboard.
Also takes the common view props: modifiers, style and testID.
Overview
Use a paste button when you want to provide a button for pasting items from
the system pasteboard into your app. The system provides a button
appearance and label appropriate to the current environment. However, you
can use view modifiers like View.buttonBorderShape(_:),
View.labelStyle(_:), and View.tint(_:) to customize the button
in some contexts.
You declare what type of items your app will accept; use a type that conforms to the doc://com.apple.documentation/documentation/coretransferable/transferable protocol. When the user taps or clicks the button, your closure receives the pasteboard items in the specified type.
In the following example, a paste button declares that it accepts a string.
When the user taps or clicks the button, the sample's closure receives an
array of strings and sets the first as the value of pastedText, which
updates a nearby Text view.
@State private var pastedText: String = ""
var body: some View {
HStack {
PasteButton(payloadType: String.self) { strings in
pastedText = strings[0]
}
Divider()
Text(pastedText)
Spacer()
}
}A paste button automatically validates and invalidates based on changes to the pasteboard on iOS, but not on macOS.
From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- View
See also
More in Controls.
- ButtonA control that initiates an action.
- ColorPickerA control used to select a color from the system color picker UI.
- DatePickerA control for selecting an absolute date.
- DisclosureGroupA view that shows or hides another content view, based on the state of a disclosure control.
- MultiDatePickerA control for picking multiple dates.
- OutlineGroupA structure that computes views and disclosure groups on demand from an underlying collection of tree-structured, identified data.
- PickerA control for selecting from a set of mutually exclusive values.
- SecureFieldA control into which people securely enter private text.
- SliderA control for selecting a value from a bounded linear range of values.
- StepperA control that performs increment and decrement actions.
- SubscriptionViewA view that subscribes to a publisher with an action.
- TableA container that presents rows of data arranged in one or more columns, optionally providing the ability to select one or more members.