clipboard icon indicating copy to clipboard operation
clipboard copied to clipboard

setString doesn't work

Open filiptronicek opened this issue 3 years ago • 32 comments

Environment

 Expo CLI 3.27.4 environment info:
    System:
      OS: Windows 10 10.0.20206
    Binaries:
      Node: 14.10.1 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.19.2 - F:\Programy\yarm\bin\yarn.CMD
      npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
    npmPackages:
      expo: ^38.0.10 => 38.0.10
      react: ^16.11.0 => 16.11.0
      react-dom: ^16.11.0 => 16.11.0
      react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
      react-native-web: ^0.11.7 => 0.11.7
    Expo Workflow: managed

Platforms

iOS, not sure about Android, it is possibly (and probably) also affected.

Versions

  • iOS: 14 beta 7
  • react-native: 0.62
  • react: 16.11.0

Description

When trying to set a string to the clipboard, it is denied and errors out:

TypeError: null is not an object (evaluating 'NativeClipboard_1.setString')

Reproducible Demo

Clipboard.setString("Test"); // Errors out

filiptronicek avatar Sep 13 '20 20:09 filiptronicek

I'm getting the same issue on iOS 13.6, react-native 0.59 - any workaround?

super-potion avatar Sep 15 '20 04:09 super-potion

I have the same issue (expo SDK 38). I ended up reverting to clipboard from react-native for now. import { Clipboard } from 'react-native'

updated: You can use import * as Clipboard from 'expo-clipboard' now. I'm usgin SDK 43.

foloinfo avatar Sep 17 '20 05:09 foloinfo

Seeing the same issue...any word on what causes this? You see it with the useHook too except you will see it here:

getString: function () {
        return NativeClipboard_1.default.getString();
    }

afreeland avatar Sep 21 '20 04:09 afreeland

I had the same problem on Android. Solved uninstalling the app and reinstalling it.

rafaellelis avatar Sep 25 '20 03:09 rafaellelis

Same here on Expo SDK 38 + 39 and @react-native-community/clipboard: ^1.2.3

Solved it by using @foloinfo solution by using import { Clipboard } from 'react-native'

benediktdertinger avatar Sep 25 '20 18:09 benediktdertinger

Same here on Expo SDK 38 + 39 and @react-native-community/clipboard: ^1.2.3

Solved it by using @foloinfo solution by using import { Clipboard } from 'react-native'

The only issue with that method is it has been declared as deprecated even though it still works. Also, it points them here to where things are broken... image

afreeland avatar Sep 28 '20 12:09 afreeland

@afreeland Yes, but it's a temporary solution, and until it gets fixed, we are stuck with it😢

filiptronicek avatar Sep 28 '20 18:09 filiptronicek

currently managed workflow for expo does not support this clipboard module. Please continue using import {Clipboard} from 'react-native' for now until the support is added to expo.

This module should work for bare workflow of expo and regular react-native via react-native-cli sorry about the inconvenience!

Naturalclar avatar Sep 30 '20 03:09 Naturalclar

Hi, Need to release the app so cannot go with deprecated one, please fix this issue ASAP :pray:

vivek2dx avatar Oct 26 '20 10:10 vivek2dx

Any update on this issue??... I'm also facing the same issue but only on iOS. It's working correctly on android.

AkshaySanas19 avatar Oct 26 '20 10:10 AkshaySanas19

There is honestly nothing I can do about using this package on a managed workflow of expo, as managed workflow of expo has predetermined sets of native modules it can use and this package isn't one of them.

Please use import {Clipboard} from 'react-native' for managed workflow of expo.

Naturalclar avatar Oct 26 '20 11:10 Naturalclar

Any solutions?

junhoyeo avatar Oct 31 '20 16:10 junhoyeo

I have the same issue, I solved it this way: import {useClipboard} from '@react-native-community/clipboard';

xhbisme avatar Nov 03 '20 08:11 xhbisme

I had the same issue with Android. Weird enough I had to do a pod install: cd ios && pod install && cd ../ after that, I ran react-native run-android and it worked.

Jorciney avatar Nov 07 '20 19:11 Jorciney

I had the same problem on Android. Solved uninstalling the app and reinstalling it.

This is works for me. But is it safe for production update? I mean when we just add this library and deploy this new updated app to play store

rukmanary avatar Dec 04 '20 06:12 rukmanary

The same problem with v1.5.1 on android and web app. I tried to use Clipboard.setString and hook realization, both have this problem.

mrKorg avatar Dec 09 '20 10:12 mrKorg

Facing the same issue...Any update on this?

Abhishek-Sankey avatar Dec 12 '20 04:12 Abhishek-Sankey

For expo users, please use the expo-clipboard module provided by expo. For non-expo users, if you're facing the issue, please provide a minimal repository that can reproduce the issue.

Naturalclar avatar Dec 13 '20 09:12 Naturalclar

I solved it

cd ios && pod install

sichan75 avatar Dec 24 '20 08:12 sichan75

don't think it's the library issue try to clean your project(reset metro bundler cache, delete build folder) and do fresh npm install and pod install. That worked for me!

Abhishek-Sankey avatar Dec 29 '20 05:12 Abhishek-Sankey

don't think it's the library issue try to clean your project(reset metro bundler cache, delete build folder) and do fresh npm install and pod install. That worked for me!

Just solved the issue by restart the metro bundler. i.e. re-run react-native start. Thank you :)

JasmineSun33 avatar Jan 04 '21 22:01 JasmineSun33

For android use this way: https://github.com/react-native-clipboard/clipboard/issues/80#issuecomment-759605515

iqorlobanov avatar Jan 13 '21 17:01 iqorlobanov

I did these, but problem is not resolved:

  1. rm -rf node_modules && npm install
  2. cd android && ./gradlew clean
  3. cd ios && pod install && cd ..

I Have this error: TypeError: Cannot read property 'setString' of null

MahmonirB avatar Jan 24 '21 13:01 MahmonirB

Same issue here, using deprecated version from "react-native" temporarily solves my issue.

import { Clipboard } from "react-native"

remi-cbd avatar Feb 13 '21 22:02 remi-cbd

I solved it by reinstalling the app

ovideliu avatar Mar 23 '21 08:03 ovideliu

this was solved for me by restarting metro.. ( i was running on IOS thought) i closed the simulator and metro and restarted again using npx react-native run-ios and it finally worked after hours of trying to figure it out! FYI, im not using expo though.

EyadAlghamdi avatar Apr 17 '21 03:04 EyadAlghamdi

A project clean in xcode and npm start -reset-cache did it for me.

flunder avatar Apr 26 '21 12:04 flunder

Did you all run pod install before building ? :P This package worked for me on the first try. Didn't need to clean XCode build cache, or npm cache, or removing the app.

kg-currenxie avatar May 20 '21 08:05 kg-currenxie

the solution is as simple as: import Clipboard from '@react-native-community/clipboard' instead of import { Clipboard } from '@react-native-community/clipboard'

kejn avatar Jul 21 '21 09:07 kejn

the same issue was fixed by manually linking the package react-native link @react-native-clipboard/clipboard. I am ushing RN0.60+ in the dox it says it will auto-link but for me, I have to do it manually and it worked

SSOURABH58 avatar Oct 02 '21 07:10 SSOURABH58