Skip to content

Instantly share code, notes, and snippets.

@PradoGuilherme
Created January 15, 2020 04:04
Show Gist options
  • Save PradoGuilherme/1a1f8ac878ddfa12038464f295bc20e9 to your computer and use it in GitHub Desktop.
Save PradoGuilherme/1a1f8ac878ddfa12038464f295bc20e9 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import Share from 'react-native-share'
import RNFetchBlob from "rn-fetch-blob";
import RNFS from 'react-native-fs'
export default class EventShare extends Component {
constructor(props) {
super(props)
this.state = {
shareEventLoading: false
}
}
shareEvent = async () => {
await this.setState({
shareEventLoading: true
})
const shareOptions = {
title: 'My Share',
message: 'To have more information, please access the app.'
}
let filePath
RNFetchBlob.config({ fileCache: true })
.fetch('GET', this.props.event.photos[0])
.then(resp => {
filePath = resp.path()
return resp.readFile('base64')
})
.then(async base64Data => {
shareOptions.url = 'data:image/png;base64,' + base64Data
try {
await Share.open(shareOptions)
await RNFS.unlink(filePath)
await this.setState({
shareEventLoading: false
})
} catch (error) {
await this.setState({
shareEventLoading: false
})
}
})
}
render() {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment