Skip to content

Commit

Permalink
feat: Share android image via expo-sharing (shootismoke#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonSpirit committed Oct 6, 2019
1 parent ca91f5b commit e689b55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 2 additions & 12 deletions App/Screens/Home/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

import React, { useContext } from 'react';
import { Platform, Share, StyleSheet, View, ViewProps } from 'react-native';
import { StyleSheet, View, ViewProps } from 'react-native';
import { NavigationInjectedProps } from 'react-navigation';

import { aboutSections } from '../../About';
Expand Down Expand Up @@ -56,17 +56,7 @@ export function Footer (props: FooterProps) {
function handleShare () {
track('HOME_SCREEN_SHARE_CLICK');

// Share doesn't currently support images on Android, so the text version
if (Platform.OS === 'ios') {
props.navigation.navigate('ShareModal');
} else {
Share.share({
title: i18n.t('home_share_title'),
message: i18n.t('home_share_message', {
cigarettes: api!.shootISmoke.cigarettes.toFixed(2)
})
});
}
props.navigation.navigate('ShareModal');
}

const renderBigButton = () => {
Expand Down
15 changes: 11 additions & 4 deletions App/Screens/ShareScreen/ShareScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

import React, { useEffect, createRef } from 'react';
import { Share, StyleSheet, View } from 'react-native';
import { Share, StyleSheet, View, Platform } from 'react-native';
import { captureRef } from 'react-native-view-shot';
import { NavigationInjectedProps } from 'react-navigation';
import * as Sharing from 'expo-sharing';

import { ShareImage } from './ShareImage';
import { i18n } from '../../localization';
Expand All @@ -37,9 +38,15 @@ export function ShareScreen (props: ShareScreenProps) {
quality: 1
});

await Share.share({
url: uri
});
if (Platform.OS === 'ios') {
await Share.share({
url: uri
});
} else {
await Sharing.shareAsync(uri, {
mimeType: 'image/png'
});
}
} catch (error) {}

handleDismiss();
Expand Down

0 comments on commit e689b55

Please sign in to comment.