
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
react-native-cross-share
Advanced tools
React Native Sharing Capabilities
npm install rnpm --global
npm install react-native-cross-share --save
rnpm link react-native-cross-share
npm install react-native-share --save
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-share
and add RNShare.xcodeproj
libRNShare.a
to your project's Build Phases
➜ Link Binary With Libraries
Cmd+R
)npm install react-native-share --save
android/app/src/main/java/[...]/MainActivity.java
import cl.json.RNSharePackage;
to the imports at the top of the fileandroid/app/src/main/java/[...]/MainApplication.java
import cl.json.RNSharePackage;
to the imports at the top of the filenew RNSharePackage()
to the list returned by the getPackages()
methodAppend the following lines to android/settings.gradle
:
include ':react-native-cross-share'
project(':react-native-cross-share').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cross-share/android')
Insert the following lines inside the dependencies block in android/app/build.gradle
:
```
compile project(':react-native-cross-share')
```
Share.open() accepts the following options.
Option | Description |
---|---|
title | Android only |
share_text | Text to share |
share_URL | Url to share |
share_file | Path of file to share or open (android & iOS only) |
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
TouchableHighlight
} from 'react-native';
import Share from 'react-native-cross-share';
class Example extends Component {
onShare() {
Share.open({
share_subject: "email subject",
share_text: "Hola mundo",
share_URL: "http://google.cl",
title: "Share Link"
},(e) => {
console.log(e);
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<TouchableHighlight onPress={this.onShare}>
<Text style={styles.instructions}>
Social Share
</Text>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('Example', () => Example);
NOTE: If both share_text and share_url are provided share_url will be concatenated to the end of share_text to form the body of the message. If only one is provided it will be used
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.