mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at rn-stack-repro 34 lines 912 B view raw
1import {Image} from 'react-native' 2import type {Dimensions} from 'lib/media/types' 3 4const sizes: Map<string, Dimensions> = new Map() 5const activeRequests: Map<string, Promise<Dimensions>> = new Map() 6 7export function get(uri: string): Dimensions | undefined { 8 return sizes.get(uri) 9} 10 11export async function fetch(uri: string): Promise<Dimensions> { 12 const Dimensions = sizes.get(uri) 13 if (Dimensions) { 14 return Dimensions 15 } 16 17 const prom = 18 activeRequests.get(uri) || 19 new Promise<Dimensions>(resolve => { 20 Image.getSize( 21 uri, 22 (width: number, height: number) => resolve({width, height}), 23 (err: any) => { 24 console.error('Failed to fetch image dimensions for', uri, err) 25 resolve({width: 0, height: 0}) 26 }, 27 ) 28 }) 29 activeRequests.set(uri, prom) 30 const res = await prom 31 activeRequests.delete(uri) 32 sizes.set(uri, res) 33 return res 34}