import { useStore } from "@/store/store"; import * as FileSystem from "expo-file-system"; import * as MediaLibrary from "expo-media-library"; import { Ionicons } from "@expo/vector-icons"; import { useRouter } from "expo-router"; import { Image, Text, View, TouchableOpacity, Alert } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; export default function WallpaperPage() { const selectedWallpaper = useStore((store) => store.selectedWallpaper); const router = useRouter(); if (!selectedWallpaper) { return null; } const imageName = selectedWallpaper.public_id.replace("wallpaper/", ""); async function downloadWallpaper() { if (!selectedWallpaper) { return; } const permStatus = await MediaLibrary.requestPermissionsAsync(); if (permStatus.status != MediaLibrary.PermissionStatus.GRANTED) { Alert.alert( "Media library access required", "Doors need access to your media library in order to save wallpapers.", ); return; } console.log( `${FileSystem.documentDirectory}${selectedWallpaper.asset_id}.${selectedWallpaper.format}`, ); const result = await FileSystem.downloadAsync( selectedWallpaper.secure_url, `${FileSystem.documentDirectory}${selectedWallpaper.asset_id}.${selectedWallpaper.format}`, ); await MediaLibrary.createAssetAsync(result.uri); Alert.alert( "Wallpaper saved successfully", "You can change the wallpaper in Settings.", ); } return ( { router.dismiss(); }} > {imageName} { downloadWallpaper(); }} > Download ); }