LynxClipboard
Copies text to the phone's clipboard and reads it back. Lynx has no navigator.clipboard. import { LynxClipboard, ClipboardError, type ClipboardErrorCode } from '@blotch/angular-lynx';
For a button that copies and says it did, add the Copy Button component.
Usage
API
LynxClipboard
Only the apps --platform builds, with ng build or ng serve, have the native module behind it, AngularLynxClipboard.
setString()
Puts text on the clipboard, in place of what it held. Resolves once it's there. Rejects with a ClipboardError.
- In the web preview, call it straight from a tap's handler, before any
await. Browsers copy only for something the person just did. - Android 13 and later show every copy themselves, in a panel at the bottom of the screen, and TalkBack says "Text copied". Check
confirmsCopiesbefore showing your own "Copied".
getString()
Resolves with the clipboard's text, or '' when it holds none, or only something else, such as an image. Rejects with a ClipboardError where there's no clipboard.
Reading asks the person first in some places. Read only when they ask to paste, never on launch:
- iOS 16 and later ask "Allow Paste?" before the app reads text another app copied. If they don't allow it, the text reads as
''. - Android 12 and later show a "pasted from your clipboard" message. Android 10 and later let only the app on screen read the clipboard.
- Browsers may ask for permission. A refusal reads as
''.
confirmsCopies
Whether the platform shows that text was copied: true on Android 13 and later. Android asks apps not to confirm a copy again, which doubles the message. The Copy Button checks it.
ClipboardError
In tests
Under the testing library, LynxClipboard keeps the text in memory, so a spec can read back what was copied:
Related
- Copy Button, a button that copies and says it did
LynxNativeModule, for the host app's own native code
