expo: [expo-clipboard] getStringAsync - fails when fetching previously selected text

Summary

getStringAsync fails when trying to fetch text from a clipboard that was previously selected and copied. More specifically from the error: “Cannot convert argument of type class android.text.SpannableString”

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

43.0.0

Environment

expo diagnostics

Expo CLI 4.12.10 environment info: System: OS: Windows 10 10.0.19042 Binaries: Node: 14.18.0 - C:\Program Files\nodejs\node.EXE npm: 7.24.1 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 4.0.0.0 AI-193.6911.18.40.6626763 npmPackages: expo: ~43.0.0 => 43.0.1 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.2 => 0.64.2 react-native-web: 0.17.1 => 0.17.1 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

See the docs’ Snack https://docs.expo.dev/versions/latest/sdk/clipboard/

  1. Open the Android emulator/device,
  2. Open Google (or anywhere you can type).
  3. Type something, select that text and copy.
  4. Open the snack, press “View Copied Text” button.
  5. Nothing happens, if using expo developer tools the following error/warning will show:

“Encountered an exception while calling native method: Exception occurred while executing exported method getStringAsync on module ExpoClipboard: Cannot convert argument of type class android.text.SpannableString”

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Have you tried using the following code to properly access the Clipboard module?

import * as Clipboard from 'expo-clipboard'

const pasteFucntion = async () => {
  const text = await Clipboard.default.getStringAsync()
  setText(text)
}

The docs seem to exclude the need for namespacing through default.

Any updates?

Will be fixed in SDK 45 by #16551.

To be specific - this happens when pasting rich/formatted text (e.g. part of a website content) which on Android is represented by Spanned/SpannableString classes, which are not implicitly convertible to String.

Hey Any Updated on this?

Happens with me too, on a ColorOS (v. 11.1) Android device. Please fix!!