How do I share expo screenshot using react native's share method?

#1

Is it possible I can use expo’s screenshot and share it using the default react native share method

 sharePost= () => {
    Share.share({
      message: `Hey look at this screenshot`,
      url: Expo.takeSnapshotAsync(),
      title: `Screen Shot`
    }, {
      dialogTitle: 'Share your screenshot',
    });
  }

#2

Yes. You can do this, but the URL you’ll get from Expo.takeSnapshotAsync() is going to be a local URL on your phone’s filesystem.

To share it effectively using that share method, you’d need to upload to a cloud service and then share that URL. The recipient of your share won’t be able to load the local URL on your phone.

#4

@ccheever How did this project do it : https://expo.io/@bacon/pillar-valley

#5

@bacon - can you chime in here?

1 Like
#6

Firstly, this is how I screenshot in pillar valley and this is how I share it. Unrelated but checkout how I remove useless share props like airdrop, when you do this it makes the share sheet open instantly instead of having that annoying 500ms lag.


Anyways, @amansahil

Will not work because Expo.takeSnapshotAsync() is an async function, meaning that it returns a Promise which you must first resolve.

const url = await Expo.takeSnapshotAsync()

Notice: the await will turn the Promise into a localUri (file://) which you can then share.


Three more important things to note are:

  1. Screenshots must reference the view they are saving
  2. You cannot screenshot GLViews on Android until v26
  3. The url prop isn’t supported in Android
3 Likes
#7

@bacon Thanks mate , this worked amazingly and thanks for the tip , removed the unnecessary options. So any workaround for android ?

1 Like
#8

For the screenshot, you’ll have to wait until v26. To share, you can pass the url to the message prop I think.

1 Like
closed #9

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.