The ClipboardManager interface was deprecated. What should I change?
The ClipboardManager interface was deprecated in favor of Clipboard interface.
Change all import androidx.compose.ui.platform.LocalClipboardManager to import androidx.compose.ui.platform.LocalClipboard and LocalClipboardManager to LocalClipboard
Make the caller function suspend or use rememberCoroutineScope().launch { ... }
If you were using function setText(AnnotatedString(text)), then you can replace it with setClipEntry(ClipEntry(ClipData.newPlainText(text, text)))
According to the Jetpack Compose tests, the replacement for hasText() is getClipEntry()?.clipData?.description?.hasMimeType("text/*")
val localClipboard = LocalClipboard.current
val scope = rememberCoroutineScope()
val clipData = ClipData.newPlainText("label", "text")
scope.launch{localClipboard.setClipEntry(clipData.toClipEntry())}
val localClipboard = LocalClipboard.current
val scope = rememberCoroutineScope()
scope.launch{localClipboard.setClipEntry(ClipEntry.withPlainText("text"))}
I haven't tested it myself yet, but Android Studio doesn't swear at syntax. As soon as I test it, I will add an answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With