React Native Share Link Example

04-Apr-2023

.

Admin

React Native Share Link Example

Hi friends,

Today, I will lean you how to share link in react native. You can easily share link in react native. We will use the share react-native example. I explained simply about react native share URL example.

So, let's start following example:

Methods


static share(content, options)

In iOS, returns a Promise which will be invoked with an object containing action and activityType. If the user dismissed the dialog, the Promise will still be resolved with action being Share.dismissedAction and all the other keys being undefined. Note that some share options will not appear or work on the iOS simulator.

In Android, returns a Promise which will always be resolved with action being Share.sharedAction.

Here, I will give you full example for simply display qrcode using react native as bellow.

Step 1 - Create project

In the first step Run the following command for create project.

expo init Nicesnippets

Step 2 - App.js

In this step, You will open App.js file and put the code.

import React, { Component } from 'react';

import { Share, View, Button,Text } from 'react-native';

class ShareExample extends Component {

onShare = async () => {

try {

const result = await Share.share({

message:

'https://www.nicesnippets.com/',

});

if (result.action === Share.sharedAction) {

if (result.activityType) {

// shared with activity type of result.activityType

} else {

// shared

}

} else if (result.action === Share.dismissedAction) {

// dismissed

}

} catch (error) {

alert(error.message);

}

};

render() {

return (

<View style={{ margin: 20 }}>

<Text style={{ marginVertical:40,fontSize: 18 }}>React Native Share link Example</Text>

<Button onPress={this.onShare} title="Share" />

</View>

);

}

}

export default ShareExample;

Step 3 - Run project

In the last step run your project using bellow command.

expo start

Output:

I hope it will help you...

#React Native