mirror of
https://github.com/balzack/databag.git
synced 2025-03-13 09:00:06 +00:00
finess download of images for android, seems very brittle
This commit is contained in:
parent
15ab5cb2e9
commit
0430403e01
@ -26,7 +26,12 @@ export function ImageAsset({ asset, dismiss }) {
|
|||||||
)}
|
)}
|
||||||
{ state.loaded && state.controls && Platform.OS !== 'ios' && (
|
{ state.loaded && state.controls && Platform.OS !== 'ios' && (
|
||||||
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
<TouchableOpacity style={styles.share} onPress={actions.download}>
|
||||||
<MatIcons name="download" size={32} color={Colors.white} />
|
{ state.downloaded && (
|
||||||
|
<MatIcons name="download-outline" size={32} color={Colors.white} />
|
||||||
|
)}
|
||||||
|
{ !state.downloaded && (
|
||||||
|
<MatIcons name="download" size={32} color={Colors.white} />
|
||||||
|
)}
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
{ state.loaded && state.controls && (
|
{ state.loaded && state.controls && (
|
||||||
|
@ -4,6 +4,7 @@ import { Image, Platform } from 'react-native';
|
|||||||
import { useWindowDimensions } from 'react-native';
|
import { useWindowDimensions } from 'react-native';
|
||||||
import Share from 'react-native-share';
|
import Share from 'react-native-share';
|
||||||
import RNFetchBlob from "rn-fetch-blob";
|
import RNFetchBlob from "rn-fetch-blob";
|
||||||
|
import RNFS from "react-native-fs";
|
||||||
|
|
||||||
export function useImageAsset(asset) {
|
export function useImageAsset(asset) {
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ export function useImageAsset(asset) {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
failed: false,
|
failed: false,
|
||||||
controls: false,
|
controls: false,
|
||||||
|
downloaded: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const conversation = useContext(ConversationContext);
|
const conversation = useContext(ConversationContext);
|
||||||
@ -73,9 +75,22 @@ export function useImageAsset(asset) {
|
|||||||
Share.open({ url: state.url })
|
Share.open({ url: state.url })
|
||||||
},
|
},
|
||||||
download: async () => {
|
download: async () => {
|
||||||
const epoch = Math.ceil(Date.now() / 1000);
|
if (!state.downloaded) {
|
||||||
const dir = Platform.OS === 'ios' ? RNFetchBlob.fs.dirs.DocumentDir : RNFetchBlob.fs.dirs.PictureDir;
|
updateState({ downloaded: true });
|
||||||
const res = await RNFetchBlob.config({path: `${dir}/databag_${epoch}.jpg`}).fetch("GET", state.url, {});
|
const epoch = Math.ceil(Date.now() / 1000);
|
||||||
|
const dir = Platform.OS === 'ios' ? RNFetchBlob.fs.dirs.DocumentDir : RNFetchBlob.fs.dirs.PictureDir;
|
||||||
|
const path = `${dir}/databag_${epoch}.jpg`
|
||||||
|
if (state.url.substring(0, 7) === 'file://') {
|
||||||
|
await RNFS.copyFile(state.url.substring(7).split('?')[0], path);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const res = await RNFetchBlob.config({path: path}).fetch("GET", state.url, {});
|
||||||
|
}
|
||||||
|
const block = await RNFS.read(path, 8, 0, 'base64');
|
||||||
|
if (block === '/9j/4AAQSkY=') {
|
||||||
|
await RNFS.scanFile(jpg);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
loaded: () => {
|
loaded: () => {
|
||||||
updateState({ loaded: true });
|
updateState({ loaded: true });
|
||||||
|
Loading…
Reference in New Issue
Block a user