`LocalClipboardManager.current` is marked as depre...
# compose
j
LocalClipboardManager.current
is marked as deprecated, but when I try to use
LocalClipboard.current
there is no way to set the clipboard text? I try to do:
val clipboard = LocalClipboard.current
And then:
Copy code
rememberCoroutineScope().launch {
  clipboard.setClipEntry(<What to put here?>)
}
setClipEntry(..)
wants a ClipEntry object But the class ClipEntry from jetbrains compose UI package has no constructor?
Copy code
/** Platform specific protocol that expresses an item in the native Clipboard. */
expect class ClipEntry {

    /**
     * Returns a [ClipMetadata] which describes the contents of this [ClipEntry]. This is an ideal
     * way to check whether to accept or reject what may be pasted from the clipboard without
     * explicitly reading the content.
     *
     * Calling this function does not trigger any content access warnings on any platform.
     */
    val clipMetadata: ClipMetadata
}
So JetBrains has deprecated a package and told me to use another package that does not work? Or am I misunderstanding something here?
j
Copy code
val clipboard = LocalClipboard.current
...
clipboard.setClipEntry(clipEntryOf(txt))
Copy code
expect fun clipEntryOf(string: String): ClipEntry

//ios
@OptIn(ExperimentalComposeUiApi::class)
actual fun clipEntryOf(string: String) = ClipEntry.withPlainText(string)

//jvm
@OptIn(ExperimentalComposeUiApi::class)
actual fun clipEntryOf(string: String) = ClipEntry(StringSelection(string))

//wasm
actual fun clipEntryOf(string: String) = ClipEntry.withPlainText(string)

//android
actual fun clipEntryOf(string: String) = ClipData.newPlainText(null, string).toClipEntry()
j
Thanks! Strange that there is no commonMain wrapper for setting the clipboard text.
i
CMP-7624 Design ClipEntry common API
👀 1