App icon indicating copy to clipboard operation
App copied to clipboard

[$250] [Image] Implement the ability to copy images to the clipboard

Open roryabraham opened this issue 5 years ago • 131 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Coming from https://github.com/Expensify/App/issues/3313

Action Performed:

Right-click or long-press on an image in a chat.

Expected Result:

  1. A context menu appears, displaying a single option: Copy image to clipboard
  2. Clicking on this option should copy the image to the clipboard, where it can be pasted somewhere else.

Note: the solution implemented must be an offline-first solution. Meaning the user should be able to copy the image to their clipboard, whether or not they have internet connection.

Actual Result:

  1. The normal context menu appears.
  2. Clicking on Copy to clipboard copies the HTML image tag to the clipboard, not the binary image itself.

Workaround:

Screenshot the image? Also you can click on it and download it.

Platform:

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.0.85-3 Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: Any additional supporting documentation Expensify/Expensify Issue URL:

Upwork job: https://www.upwork.com/jobs/~012fd9a807faaf42aa View all open jobs on Upwork

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01b3973ec74ce159e9
  • Upwork Job ID: 1782953316490067968
  • Last Price Increase: 2024-05-01

roryabraham avatar Aug 12 '21 21:08 roryabraham

Okay, there was a fair deal of discussion over in https://github.com/Expensify/App/issues/3313 and other issues, but the task at hand here is to:

  1. (internal) Create an Expensify/ fork of https://github.com/react-native-clipboard/clipboard
  2. Create a separate fork of https://github.com/react-native-clipboard/clipboard for local testing.
  3. Provide a complete implementation of this issue in your separate fork.
  4. Point this project and your fork for local testing.
  5. Add a new context menu type for images, display it when images are right-clicked or long-pressed. This PR might serve as a useful guide.
  6. Once that's working, submit a PR from your fork of react-native-clipboard to the Expensify/react-native-clipboard fork.
  7. Also submit a PR from your fork of react-native-clipboard to the upstream project.
  8. Create a PR in this repo with your implementation from step 5 above, but point the project at the Expensify/react-native-clipboard fork instead of your personal one. (should be on HOLD until the PR from step 6 is merged.
  9. Lastly, if/when your PR from step 7 is merged by the project maintainers, create another PR to point this repo at the upstream repo: https://github.com/react-native-clipboard/clipboard

roryabraham avatar Aug 12 '21 21:08 roryabraham

No Upwork job created for this yet.

roryabraham avatar Aug 16 '21 18:08 roryabraham

Upwork job created here: https://www.upwork.com/jobs/~011432fcc2168828e1

@Drewfergusson would you be interested in this? Given you implemented the first part.

puneetlath avatar Aug 16 '21 18:08 puneetlath

@puneetlath things have gotten quite a bit busier for me lately so I'm going to have to pass.

Drewfergusson avatar Aug 17 '21 13:08 Drewfergusson

@puneetlath, @roryabraham Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

MelvinBot avatar Aug 19 '21 19:08 MelvinBot

No new proposals here

roryabraham avatar Aug 20 '21 01:08 roryabraham

@puneetlath, @roryabraham Whoops! This issue is 2 days overdue. Let's get this updated quick!

MelvinBot avatar Aug 23 '21 19:08 MelvinBot

@puneetlath, @roryabraham it looks like no one is assigned to work on this job. Please double the price or add a comment stating why the job isn't being doubled.

MelvinBot avatar Aug 23 '21 19:08 MelvinBot

Updated price to $2000.

puneetlath avatar Aug 23 '21 22:08 puneetlath

Proposal

Currently used setString function for copy to clipboard for attachement image

And when paste, it is not parsing content correctly in handlePaste for textinput

image

embeddedImages length always showing 0

Reason: setString to clipboard making extra span tag image element converted to string

To fix issue

  • Get image element text from clipboard image

  • Convert it to html tag from string image

  • Attached Working Video

https://user-images.githubusercontent.com/12084368/130595083-442b227f-a1e7-4a9e-b71e-7b7304144234.mov

Please review and give me feedback @roryabraham , @puneetlath

MTN718 avatar Aug 24 '21 09:08 MTN718

@MTN718

Reason: setString to clipboard making extra span tag image element converted to string

Sorry, I'm having difficulty understanding this. Can you help me understand this better?


Other than that, there are two main concerns I have with your proposal:

  1. Keep in mind that this is a react-native codebase, so we need a solution that works not only on web, but also on iOS and Android. Ideally, we would create a solution that works for both iOS/Android and react-native-web, so that we don't need two separate implementations. See the following resources:
    • Expensify/App Philosophy, particularly section 5 titled "Cross Platform 99.9999%"
    • https://github.com/react-native-clipboard/clipboard/issues/6
    • https://github.com/Expensify/App/issues/4629#issuecomment-897981246
  2. Also, can you verify with your existing solution that the image binary is copied to the clipboard such that it can be pasted into another program, such as Notes, Google Docs, or Microsoft Word?

roryabraham avatar Aug 24 '21 17:08 roryabraham

Proposal


Use native share workflow for mobile (with react-native-share ), and keep web/desktop version with the "Copy to Clipboard" Context menu.


Explanation: UX is increased, by having more options: with just one step users can copy the content, or send it to other apps like WhatsApp, Slack, Note (or any other workflow they prefer)


Solution

Create a <Sharable/> component, similar to <PressableWithSecondaryInteraction/>, that instead of showing the context menu, it would show the native ios/android share menu. This is the same behavior that slack takes when long-pressing a link for example:

This is how it would look like in android and ios:

anboia avatar Aug 24 '21 19:08 anboia

@anboia That is an interesting alternate solution, I love it!

That said, I think it should really be a separate context menu option. I recommend that you create a separate issue in this repo to propose adding a share option to the context menu using the native share menu, and we can discuss over there. Plus, if we decide to move forward with this new feature, there's an additional bonus we pay to contributors if you open an issue and also implement the solution. 🤑

roryabraham avatar Aug 24 '21 19:08 roryabraham

Found solution for web version.

https://user-images.githubusercontent.com/12084368/130682096-fcb1d3a1-afe9-4ef2-b59d-6857e41fceb1.mov

Read image blob data from url and make clipboard item and write to clipboard Used clipboard.write instead of setString One Notice: Image url should be png file. clipboard support only image/png type. can't save jpg file to clipboard So we should be discuss about convert image jpg to png from server or frontend.

https://user-images.githubusercontent.com/12084368/130692002-4fb74592-6db5-4fb4-903a-ba8a691d325d.mov

MTN718 avatar Aug 24 '21 19:08 MTN718

@roryabraham one question, currently how to open context menu in the ios? long press on image is working?

MTN718 avatar Aug 24 '21 19:08 MTN718

It's mobile web version

https://user-images.githubusercontent.com/12084368/130682485-44ac9a44-5f73-403d-b8f7-f53d76b67f74.mov

MTN718 avatar Aug 24 '21 20:08 MTN718

@roryabraham one question, currently how to open context menu in the ios? long press on image is working?

Yeah, longPress should open the context menu.

roryabraham avatar Aug 24 '21 21:08 roryabraham

One Notice: Image url should be png file. clipboard support only image/png type. can't save jpg file to clipboard So we should be discuss about convert image jpg to png from server or frontend.

Really? I've never encountered this issue

roryabraham avatar Aug 24 '21 21:08 roryabraham

@roryabraham I think we already have an open issue #1294 for share menus.

parasharrajat avatar Aug 24 '21 21:08 parasharrajat

@parasharrajat https://github.com/Expensify/App/issues/1294 is slightly different – I believe that's about adding New Expensify as an option in native share menus, not about exposing native share menus from within New Expensify

roryabraham avatar Aug 24 '21 21:08 roryabraham