File sharing is a very common feature in many apps. For this purpose on React Native, we can use the lib React Native Share
.
Install React Native Share
$ npm install react-native-share --save
One more step for iOS
$ npx pod-install
# or
$ cd ios && pod install
Share a file
import React, {useCallback} from 'react';
import {View, Button} from 'react-native';
import Share from 'react-native-share';
export default function ShareAudio () {
const onShareAudio = useCallback(function () {
Share.open({
url: `file:///data/data/com.yourapp/files/audio.mp3`,
type: 'audio/mp3',
});
}, []);
return (
<View>
<Button
title="Share audio"
onPress={onShareAudio}
/>
</View>
);
};
Top comments (4)
so i have a Question , I am planning to build an file transfer app , which share files between applications , and save it to the local file system , just like
Share It
,so can i use react-native-share for that purpose .
Thanks for writing up!
Thank you for your feedback :D
How to share a video. can you help me please.