import * as MediaLibrary from "expo-media-library"; import * as ImageManipulator from "expo-image-manipulator"; import { Dimensions } from "react-native"; const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen"); export async function requestGalleryPermission(): Promise { const { status } = await MediaLibrary.requestPermissionsAsync(); return status === "granted"; } export async function getRecentPhotos( count: number = 50, offset: number = 0 ): Promise<{ assets: MediaLibrary.Asset[]; hasMore: boolean }> { const query = new MediaLibrary.Query() .eq(MediaLibrary.AssetField.MEDIA_TYPE, MediaLibrary.MediaType.IMAGE) .orderBy({ key: MediaLibrary.AssetField.CREATION_TIME, ascending: false, }) .limit(count) .offset(offset); const assets = await query.exe(); return { assets, hasMore: assets.length === count, }; } export async function prepareImageForWallpaper( uri: string ): Promise { const result = await ImageManipulator.manipulateAsync( uri, [ { resize: { width: SCREEN_WIDTH * 2, height: SCREEN_HEIGHT * 2, }, }, ], { compress: 0.95, format: ImageManipulator.SaveFormat.JPEG } ); return result.uri; }