switching share to save for android

This commit is contained in:
Roland Osborne 2024-06-06 18:20:53 -07:00
parent d4b1eb2100
commit 15ab5cb2e9
2 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { Text, View, Image, ActivityIndicator, TouchableOpacity } from 'react-native';
import { Text, View, Image, ActivityIndicator, TouchableOpacity, Platform } from 'react-native';
import { useImageAsset } from './useImageAsset.hook';
import { styles } from './ImageAsset.styled';
import Colors from 'constants/Colors';
@ -19,12 +19,16 @@ export function ImageAsset({ asset, dismiss }) {
style={{ ...styles.main, width: state.imageWidth, height: state.imageHeight }}
resizeMode={FastImage.resizeMode.contain} />
)}
{ state.loaded && state.controls && (
<TouchableOpacity style={styles.share} onPress={actions.download}>
{ state.loaded && state.controls && Platform.OS === 'ios' && (
<TouchableOpacity style={styles.share} onPress={actions.share}>
<MatIcons name="share-variant-outline" size={32} color={Colors.white} />
</TouchableOpacity>
)}
{ state.loaded && state.controls && Platform.OS !== 'ios' && (
<TouchableOpacity style={styles.share} onPress={actions.download}>
<MatIcons name="download" size={32} color={Colors.white} />
</TouchableOpacity>
)}
{ state.loaded && state.controls && (
<TouchableOpacity style={styles.close} onPress={dismiss}>
<Ionicons name={'close'} size={32} color={Colors.white} />

View File

@ -1,8 +1,9 @@
import { useState, useRef, useEffect, useContext } from 'react';
import { ConversationContext } from 'context/ConversationContext';
import { Image } from 'react-native';
import { Image, Platform } from 'react-native';
import { useWindowDimensions } from 'react-native';
import Share from 'react-native-share';
import RNFetchBlob from "rn-fetch-blob";
export function useImageAsset(asset) {
@ -68,9 +69,14 @@ export function useImageAsset(asset) {
const { width, height } = e.nativeEvent;
updateState({ imageRatio: width / height });
},
download: () => {
share: () => {
Share.open({ url: state.url })
},
download: async () => {
const epoch = Math.ceil(Date.now() / 1000);
const dir = Platform.OS === 'ios' ? RNFetchBlob.fs.dirs.DocumentDir : RNFetchBlob.fs.dirs.PictureDir;
const res = await RNFetchBlob.config({path: `${dir}/databag_${epoch}.jpg`}).fetch("GET", state.url, {});
},
loaded: () => {
updateState({ loaded: true });
},