react-native-clipboard / clipboard

React Native Clipboard API for both iOS and Android.
MIT License
688 stars 138 forks source link

Clipboard use notification in iOS 14 #56

Open Peretz30 opened 4 years ago

Peretz30 commented 4 years ago

Environment

System: OS: macOS 10.15.5 CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz Memory: 207.46 MB / 10.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 14.3.0 - /usr/local/bin/node Yarn: 1.15.2 - /usr/local/bin/yarn npm: 6.14.5 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: API Levels: 23, 25, 26, 27, 28 Build Tools: 23.0.1, 25.0.3, 26.0.1, 26.0.3, 27.0.0, 27.0.3, 28.0.0, 28.0.3 System Images: android-28 | Google Play Intel x86 Atom, android-R | Google APIs Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 3.4 AI-183.6156.11.34.5692245 Xcode: 11.5/11E608c - /usr/bin/xcodebuild Languages: Java: 1.8.0_171 - /usr/bin/javac Python: 2.7.15 - /usr/local/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.11.0 => 16.11.0 react-native: 0.62.2 => 0.62.2 npmGlobalPackages: react-native: Not Found

Platforms

iOS 14

Versions

Description

On app start, I have this message in new iOS, but my app read nothing from clipboard. Only uses clipboard in some places of the app to save text. image

Reproducible Demo

Install library

ghobashy commented 4 years ago

I'm facing the same issue, is there any solution or workaround for this issue?

fritzfr commented 4 years ago

Interesting.

Looking at the recent TikTok news regarding exactly this behaviour, this should better be investigated.

EricWiener commented 4 years ago

Pre-iOS 14, the way to check clipboard content was to look at the data in it, so this is why you get the notification you pasted from the clipboard. The API for iOS 14 has been updated to allow you to check clipboard content without actually looking at the data (and avoiding the notification).

ghobashy commented 4 years ago

Actually i found that my issue was not with react native clipboard, it was coming from firebase dynamic links v6.3 once i commented out Firebase/DynamicLinks dependency in my PodFile it went away.

Hope that helps.

filiptronicek commented 4 years ago

Pre-iOS 14, the way to check clipboard content was to look at the data in it, so this is why you get the notification you pasted from the clipboard. The API for iOS 14 has been updated to allow you to check clipboard content without actually looking at the data (and avoiding the notification).

@EricWiener is this implemented with this library? I think this API would really benefit a lot of RN apps. (if not I will probably create a separate issue for it)

EricWiener commented 4 years ago

Pre-iOS 14, the way to check clipboard content was to look at the data in it, so this is why you get the notification you pasted from the clipboard. The API for iOS 14 has been updated to allow you to check clipboard content without actually looking at the data (and avoiding the notification).

@EricWiener is this implemented with this library? I think this API would really benefit a lot of RN apps. (if not I will probably create a separate issue for it)

@filiptronicek It hasn't been implemented here yet (I just took a look at the commits). I'd be happy to work on it, but I won't be able to start until August 21st (restricted by current job).

filiptronicek commented 4 years ago

Nice then, I will create an issue, and we'll go from there! @EricWiener

focux commented 3 years ago

For those having this issue, instead of using the useClipboard hook, use the Clipboard object depending on what you want to do. If you use the useClipboard hook, it gets what is in the clipboard when the screen is mounted, however, if you use the Clipboard function, you can read the clipboard only when you need to.

samzmann commented 3 years ago

@focux Do you have an example of something that works?

I build a custom hook using the Clipboard methods instead of useClipboard, but still see the toast message in some cases.

export const useCustomClipboard = () => {
  const [clipboardContent, setClipboardContent] = useState('')

  // This effect gets the native Clipboard content on first mount
  // and sets clipboardContent accordingly
  useEffect(() => {
    Clipboard.getString().then(setClipboardContent)
  }, [])

  // This effect sets native Clipboard string when clipboardContent changes
  useEffect(() => {
    Clipboard.setString(clipboardContent)
  }, [clipboardContent])

  return [clipboardContent, setClipboardContent]
}

Weirdly, I consistently get the toast message every time I call Clipboard.getString() with a new string in the clipboard...