Skip to content

Commit

Permalink
Improve data exporter to share data with better names (#174)
Browse files Browse the repository at this point in the history
* Write file to filesystem before sharing

* Enhance sharing data output

- Updated react-native-share to 3.1.0 because of [issue](react-native-share/react-native-share#702)
- Separated out iOS specific and android share logic as the behaviors for sharing are significanlty different even for a simple case like filename
  • Loading branch information
tushar-dadlani authored Mar 24, 2020
1 parent 5a1c006 commit bcb3861
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
62 changes: 49 additions & 13 deletions app/views/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import {
View,
Text,
Image,
Platform,
Dimensions,
TouchableOpacity,
BackHandler,
} 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 { convertPointsToString } from '../helpers/convertPointsToString';
import Share from 'react-native-share';
Expand All @@ -27,14 +26,15 @@ const width = Dimensions.get('window').width;

const base64 = RNFetchBlob.base64;

//import RNShareFile from 'react-native-file-share';
// require the module
// var RNFS = require('react-native-fs');

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

onShare = async () => {
OnShare = async () => {
try {
const locationArray = await GetStoreData('LOCATION_DATA');
var locationData;
Expand All @@ -45,10 +45,43 @@ class ExportScreen extends Component {
locationData = [];
}

b64Data = base64.encode(JSON.stringify(locationData));
Share.open({
url: 'data:string/txt;base64,' + b64Data,
})
const jsonData = base64.encode(JSON.stringify(locationData));
const title = 'PrivateKit_.json';
const filename = 'PrivacyKit_.json';
const message = 'Here is my location log from Private Kit.';
const url = 'data:application/json;base64,' + jsonData;
const options = Platform.select({
ios: {
activityItemSources: [
{
placeholderItem: { type: 'url', content: url },
item: {
default: { type: 'url', content: url },
},
subject: {
default: title,
},
linkMetadata: { originalUrl: url, url, title },
},
{
placeholderItem: { type: 'text', content: message },
item: {
default: { type: 'text', content: message },
message: null, // Specify no text to share via Messages app.
},
},
],
},
default: {
title,
subject: title,
url: url,
message: message,
filename: filename,
},
});

Share.open(options)
.then(res => {
console.log(res);
})
Expand Down Expand Up @@ -98,7 +131,7 @@ class ExportScreen extends Component {
</Text>
<TouchableOpacity
style={styles.buttonTouchable}
onPress={this.onShare}>
onPress={this.OnShare}>
<Text style={styles.buttonText}>{languages.t('label.share')}</Text>
</TouchableOpacity>
<Text style={[styles.sectionDescription, { marginTop: 36 }]}>
Expand All @@ -119,6 +152,13 @@ const styles = StyleSheet.create({
color: colors.PRIMARY_TEXT,
backgroundColor: colors.WHITE,
},
headerTitle: {
textAlign: 'center',
fontWeight: 'bold',
fontSize: 38,

padding: 0,
},
subHeaderTitle: {
textAlign: 'center',
fontWeight: 'bold',
Expand Down Expand Up @@ -183,10 +223,6 @@ const styles = StyleSheet.create({
height: 18,
width: 18.48,
},
headerTitle: {
fontSize: 24,
fontFamily: 'OpenSans-Bold',
},
sectionDescription: {
fontSize: 16,
lineHeight: 24,
Expand Down
6 changes: 2 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ PODS:
- React
- RNScreens (2.0.0-alpha.12):
- React
- RNShare (3.0.0):
- RNShare (3.1.1):
- React
- RNZipArchive (5.0.1):
- React
Expand Down Expand Up @@ -438,8 +438,6 @@ SPEC CHECKSUMS:
React-jsi: cb2cd74d7ccf4cffb071a46833613edc79cdf8f7
React-jsiexecutor: d5525f9ed5f782fdbacb64b9b01a43a9323d2386
React-jsinspector: fa0ecc501688c3c4c34f28834a76302233e29dc0
react-native-google-maps: 0a989abda71059db2caa98b9dacca7a8f38a47d0
react-native-maps: f4b89da81626ad7f151a8bfcb79733295d31ce5c
react-native-safe-area-context: d288138da2c800caa111f9352e9333f186a06ead
react-native-viewpager: a7b438ca32c57b2614ece2a123e7fe116f743131
react-native-webview: fcb5f377aadc216273300f452ee0d321fb85809b
Expand All @@ -461,7 +459,7 @@ SPEC CHECKSUMS:
RNGestureHandler: 911d3b110a7a233a34c4f800e7188a84b75319c6
RNI18n: e2f7e76389fcc6e84f2c8733ea89b92502351fd8
RNScreens: 254da4b84f25971cbb30ed3ddc84131f23cac812
RNShare: 0e19ddb0bf338b62702ce1d9e001ee14effa68a8
RNShare: a4d8a4e7b85194fcc05f6753bd484f4eba6b833d
RNZipArchive: 87111bb6130a38edd68c8d2059d46ac94d53ffe4
SSZipArchive: fa16b8cc4cdeceb698e5e5d9f67e9558532fbf23
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"react-native-push-notification": "^3.1.9",
"react-native-safe-area-context": "0.6.0",
"react-native-screens": "2.0.0-alpha.12",
"react-native-share": "^3.0.0",
"react-native-share": "^3.1.0",
"react-native-webview": "^8.1.2",
"react-native-zip-archive": "^5.0.1",
"rn-fetch-blob": "^0.12.0"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5767,10 +5767,10 @@ [email protected]:
dependencies:
debounce "^1.2.0"

react-native-share@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-native-share/-/react-native-share-3.0.0.tgz#5e158f773ebc91e35fbe48ffe21c0073c2c8f41a"
integrity sha512-5P/Fhou5jW1yY475h+wIR+VZAUZ1Gnx8N4QKGToOLNo1yUhDeLxYRhm3bGCcS/MEy35NOZ222/43SQGfUzCl/g==
react-native-share@^3.1.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/react-native-share/-/react-native-share-3.1.1.tgz#db6bd75318c747fee565f8cc012dd0a846cecca9"
integrity sha512-3BwSo3lhrUlqqx0LxHF5tyKc927UI6N6pu+o2+agdYjtfdVLeUeyYIjkdYGobcIvviTr4qcr9FJ0AfUCSHvlGQ==

react-native-webview@^8.1.2:
version "8.1.2"
Expand Down

0 comments on commit bcb3861

Please sign in to comment.