forked from Memmy-App/memmy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as FileSystem from "expo-file-system"; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as Permissions from "expo-permissions"; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as MediaLibrary from "expo-media-library"; | ||
|
||
const downloadAndSaveImage = async (src: string): Promise<boolean> => { | ||
const fileName = src.split("/").pop(); | ||
const filePath = FileSystem.documentDirectory + fileName; | ||
|
||
try { | ||
const { status } = await Permissions.askAsync( | ||
Permissions.MEDIA_LIBRARY_WRITE_ONLY | ||
); | ||
|
||
if (status === "granted") { | ||
const res = await FileSystem.downloadAsync(src, filePath); | ||
saveImage(res.uri); | ||
return true; | ||
} | ||
|
||
return false; | ||
} catch (e) { | ||
console.log(e); | ||
return false; | ||
} | ||
}; | ||
|
||
const saveImage = async (filePath: string) => { | ||
try { | ||
MediaLibrary.saveToLibraryAsync(filePath).then(); | ||
} catch (e) { | ||
console.log("Error: ", e); | ||
} | ||
}; | ||
|
||
export default downloadAndSaveImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5144,6 +5144,11 @@ [email protected]: | |
compare-versions "^3.4.0" | ||
invariant "^2.2.4" | ||
|
||
expo-permissions@~14.1.1: | ||
version "14.1.1" | ||
resolved "https://registry.yarnpkg.com/expo-permissions/-/expo-permissions-14.1.1.tgz#6fc4ec5caf712df3ff2d9b7b831a6d9116f1d2b8" | ||
integrity sha512-hOuAOBz+ZLsSJ3E8Ere/oA7YIYLNGf9fCApTi9OQmeJyCBsBHynf1yqMfVVpuDcCMixZ2XzsWlScq75f+7U1dQ== | ||
|
||
expo-splash-screen@~0.18.1: | ||
version "0.18.2" | ||
resolved "https://registry.yarnpkg.com/expo-splash-screen/-/expo-splash-screen-0.18.2.tgz#dde246204da875785ba40c7143a70013cdefdbb6" | ||
|