show copied message when asset copied

This commit is contained in:
balzack 2023-08-13 22:28:56 -07:00
parent 6b60098ff3
commit acead8f30b
3 changed files with 19 additions and 2 deletions

View File

@ -48,6 +48,11 @@ export function BinaryAsset({ asset, dismiss }) {
{ state.downloading && ( { state.downloading && (
<ActivityIndicator color={Colors.white} size="large" /> <ActivityIndicator color={Colors.white} size="large" />
)} )}
<View style={styles.copied}>
{ state.copied && (
<Text style={styles.copiedText}>Copied to App Directory</Text>
)}
</View>
</View> </View>
<Text style={styles.extension}>{ asset.extension }</Text> <Text style={styles.extension}>{ asset.extension }</Text>
</View> </View>

View File

@ -26,6 +26,14 @@ export const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
}, },
copied: {
height: 32,
paddingTop: 8,
},
copiedText: {
color: Colors.white,
fontSize: 18,
},
extension: { extension: {
textAlign: 'center', textAlign: 'center',
fontSize: 48, fontSize: 48,

View File

@ -12,6 +12,7 @@ export function useBinaryAsset() {
width: 1, width: 1,
height: 1, height: 1,
downloading: false, downloading: false,
copied: false,
}); });
const dimensions = useWindowDimensions(); const dimensions = useWindowDimensions();
@ -45,7 +46,8 @@ export function useBinaryAsset() {
src = blob.path(); src = blob.path();
} }
if (Platform.OS === 'iOS') { if (Platform.OS === 'ios') {
const path = `${RNFetchBlob.fs.dirs.DocumentDir}` const path = `${RNFetchBlob.fs.dirs.DocumentDir}`
const dst = `${path}/${label}.${extension.toLowerCase()}` const dst = `${path}/${label}.${extension.toLowerCase()}`
if (RNFetchBlob.fs.exists(dst)) { if (RNFetchBlob.fs.exists(dst)) {
@ -61,8 +63,10 @@ export function useBinaryAsset() {
RNFetchBlob.fs.unlink(dst); RNFetchBlob.fs.unlink(dst);
} }
else { else {
const copy = RNFS.ExternalDirectoryPath + "/" label + "." + extension; const copy = RNFS.ExternalDirectoryPath + "/" + label + "." + extension;
RNFS.copyFile(src, copy); RNFS.copyFile(src, copy);
updateState({ copied: true });
setTimeout(() => updateState({ copied: false }), 2000);
} }
updateState({ downloading: false }); updateState({ downloading: false });
} }