mirror of
https://github.com/balzack/databag.git
synced 2025-04-20 08:35:15 +00:00
switching share to save for android
This commit is contained in:
parent
d4b1eb2100
commit
15ab5cb2e9
@ -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} />
|
||||
|
@ -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 });
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user