Skip to content

Commit

Permalink
Add file based sharing (Path-Check#38)
Browse files Browse the repository at this point in the history
 - Allows the file to be shared instead of raw string

NOTES: This requires accessing the filesystem when you do an Export. Potentially we'll need to warn people this is going to cause a popup.
  • Loading branch information
tremblerz authored and SamMakesThings committed Mar 22, 2020
1 parent faf95ac commit e8a0deb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
54 changes: 29 additions & 25 deletions app/views/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,49 @@ import {
View,
Text,
Alert,
Image,
Share
Image
} from 'react-native';

import colors from "../constants/colors";
import WebView from 'react-native-webview';
import Button from "../components/Button";
import { GetStoreData } from '../helpers/General';
import Share from 'react-native-share';
import RNFetchBlob from 'rn-fetch-blob';

const base64 = RNFetchBlob.base64


//import RNShareFile from 'react-native-file-share';


class ExportScreen extends Component {
constructor(props) {
super(props);
}

onShare = async () => {
try {
const locationArray = await GetStoreData('LOCATION_DATA');
var locationData;

if (locationArray !== null) {
locationData = JSON.parse(locationArray);
} else {
locationData = [];
}

const result = await Share.share({
message: JSON.stringify(locationData)
});

if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
try {
const locationArray = await GetStoreData('LOCATION_DATA');
var locationData;

if (locationArray !== null) {
locationData = JSON.parse(locationArray);
} else {
// shared
locationData = [];
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
console.log(error.message);

b64Data = base64.encode(JSON.stringify(locationData));
Share.open({
url: "data:string/txt;base64," + b64Data
}).then(res => {
console.log(res);
})
.catch(err => {
console.log(err.message, err.code);
})
} catch (error) {
console.log(error.message);
}
};

Expand All @@ -55,6 +58,7 @@ class ExportScreen extends Component {
}

render() {

return (
<SafeAreaView style={styles.container}>
<View style={styles.headerContainer}>
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"react-native-gesture-handler": "~1.5.0",
"react-native-safe-area-context": "0.6.0",
"react-native-screens": "2.0.0-alpha.12",
"react-native-webview": "^8.1.2"
"react-native-share": "^3.0.0",
"react-native-webview": "^8.1.2",
"rn-fetch-blob": "^0.12.0"
},
"devDependencies": {
"@babel/core": "^7.8.6",
Expand Down

0 comments on commit e8a0deb

Please sign in to comment.