Rick Regan
06/21/2021, 5:40 PMLocalClipboardManager.current.setText(AnnotatedString("Copied to clipboard"))
. But how can I copy to the clipboard from a callback? I want to copy the state of a Text
when a "copy all" icon button is pressed. (The composable SelectionContainer
is not suitable for my app for several reasons.)Lukasz Burcon
06/21/2021, 8:10 PMRick Regan
06/21/2021, 8:48 PMLukasz Burcon
06/21/2021, 9:48 PMmutableState
is defined and remembered. Then that mutableState
would be passed as a parameter both to a TextField and IconButton (or anything you’d like to use). In the TextField you’d have to update the state whenever the text changes, and in the IconButton you’d just have to implement an onClick like this
val localClipboardManager = LocalClipboardManager.current
IconButton(
icon = xxx,
onClick = {
localClipboardManager.setText(AnnotatedString("Copied to clipboard"))
}
}
Look how I got the LocalClipboardManager instance outside of the onClick
callback so I can use it in a non-Composable function 🙂Rick Regan
06/22/2021, 11:38 AM