Share extension react native - expo
Asked Answered
M

1

5

I have created a react-native app using expo. Now I am looking for share-extension to the app to import CSV data from email attachment to my app.

I have tried npm package but that does not work for me(I was not able to build my project with that npm package in Xcode)

I think react-native or expo does not have any share API

In this picture, you can see how he got the option to import data into the app.

I understand that without share extension API, I think react-native and Expo both are useless because you can create the app but you don't expand it.

Looking for the solution or any other alternate solution.

Materialist answered 1/8, 2018 at 21:17 Comment(5)
i think this package will solve your problem github.com/alinz/react-native-share-extensionExegete
@CiprianB To be very honest I don't have much experience with Objective - C.Materialist
@CiprianB Are you able to explain in detail or is there any video of doing this thing?Materialist
I saw the description provided by author but did not understand anything.Materialist
At this moment you don't have alternative for sharing data with your app. You need to install that npm, and you have all the steps described very well. PS. Keep in mind, with this approach you will edit the native apps(ios + android)Exegete
D
8

I'm afraid this is not possible with expo.

First of all, are you looking for a way to create your own extension, or do you just want your app to be in the "open with list" that you have in the screenshot on the right? (Sharing and "open with" are two distinct things.)

If you just want your app to be listed in the standard "open with list", you do not need to use github.com/alinz/react-native-share-extension since it serves a different purpose. To quote the repo:

This is a helper module which brings react native as an engine to drive share extension for your app.

So with the package you can use react native to create your own share extension

To get your app into the "open with list", you need to go to target settings and change it according to the screenshot (example for MS word). Read more about it here. However, I'm afraid you won't be able to do this with expo without ejecting.

enter image description here

How to get the url of the file in react-native? You need to make sure that libRCTLinking.a is in the Link Binary with Libraries in Xcode (it'll probably be there already). And then you can follow the docs and call Linking.getInitialURL to get the file url. Then it really depends on what you want to do with the file. If you need something complicated, you'll likely need to write native code. If you just want to upload the file to some server, then you can make use of blob support that was added to RN 0.54 in this commit. An example of how to use the blob support is here.

Daveen answered 1/11, 2018 at 22:25 Comment(11)
I like your answer and thanks for your most useful information. I just want, my app in "open with list". I was miss understood by share extension.Materialist
Thanks for your answer! Is that possible to handle incoming file from react native? and am I able to build ios app after ejecting and editing the Info as described in screenshot ?Materialist
@RutulPatel I have expanded the answer. Well, yes, you should be able to build the app after ejecting.Daveen
from where should I able to handle that incoming data to the app from react native?Materialist
@RutulPatel please see the docs link in the answer: facebook.github.io/react-native/docs/linkingDaveen
So, I tried this thing. but now I have minor confusion, I detached from expo but now there is no mean to handle this by Linking. because if I make changes am I able to build project with expo again or I have to do that manually from Xcode ?Materialist
Hey @vonovak, Now I am getting this kind of URL 'exp:///private/var/mobile/Containers/Data/Application/7E55EB55-7C49-4C0C-B4CB-63AC4F49689E/Documents/Inbox/matters-3.csv' do you know how can I read file ?Materialist
I got this error [Unhandled promise rejection: Error: File 'file:///private/var/mobile/Containers/Data/Application/7E55EB55-7C49-4C0C-B4CB-63AC4F49689E/Documents/Inbox/matters-3.csv' isn't readable.]Materialist
hard to say, I think you can open a new question for this and provide more infoDaveen
I know you are an expert. can you please take look here.. #53161252Materialist
Do you have any idea why my file is copied into private storage?.Materialist

© 2022 - 2024 — McMap. All rights reserved.