项目作者: cdimascio

项目描述 :
iOS share sheet for React Native
高级语言: Objective-C
项目地址: git://github.com/cdimascio/react-native-share-sheet.git
创建时间: 2016-01-20T17:44:13Z
项目社区:https://github.com/cdimascio/react-native-share-sheet

开源协议:MIT License

下载


react-native-share-sheet

Use the iOS share sheet from React Native



Install

  1. npm install react-native-share-sheet
  2. In XCode, in the project navigator, right click Libraries -> Add Files to [YourProjectName]
  3. Go to node_modules/react-native-share-sheet/RNShareSheet and add RNShareSheet.m, RNShareSheet.swift, RNShareSheet-Bridging-Header.h
  4. Rename RNShareSheet-Bridging-Header.h to [YourProjectName]-Bridging-Header.h

Use

import { ShareSheet } from 'react-native-share-sheet

  1. const share = {
  2. imageUrl: 'http://facebook.github.io/react-native/img/opengraph.png',
  3. text: 'some super cool text'
  4. }
  5. ShareSheet.open(share)

Example

  1. import React, {
  2. AppRegistry,
  3. Component,
  4. StyleSheet,
  5. Text,
  6. TouchableOpacity,
  7. View
  8. } from 'react-native';
  9. import { ShareSheet } from 'NativeModules'
  10. const share = {
  11. url: 'http://facebook.github.io/react-native/',
  12. text: 'some super cool text'
  13. };
  14. class ShareSheetDemo extends Component {
  15. render() {
  16. return (
  17. <View style={styles.container}>
  18. <TouchableOpacity onPress={() => ShareSheet.open(share)}>
  19. <Text style={styles.text}>
  20. Share
  21. </Text>
  22. </TouchableOpacity>
  23. </View>
  24. );
  25. }
  26. }
  27. const styles = StyleSheet.create({
  28. container: {
  29. flex: 1,
  30. justifyContent: 'center',
  31. alignItems: 'center',
  32. backgroundColor: '#F5FCFF',
  33. },
  34. text: {
  35. backgroundColor: 'lightblue',
  36. padding: 10,
  37. fontSize: 20,
  38. textAlign: 'center',
  39. margin: 10,
  40. },
  41. });
  42. AppRegistry.registerComponent('ShareSheet', () => ShareSheetDemo);

Options

Property Value
text optional string
imageUrl optional url string or asset library string
url optional url of the web page to share

If both imageUrl and url specified, imageUrl will appear as the share preview

Examples

imageUrl

  • Asset Library path * assets-library://asset/asset.JPG?id=FF5F38D6-AACC-1116-3091-AF3499CD923D&ext=JPG
  • Image Url * http://facebook.github.io/react-native/img/opengraph.png

text

  • #ReactNative is awesome!

url

MISC

Works great with react-native-camera!

Snap a pic with react-native-camera and share it with react-native-share-sheet. react-native-camera will return the new photo’s asset library path which can be shared using react-native-share-sheet

License

MIT