Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get thumb image from Photolibrary image?

Currently i am fetching memory issue because i am loading direct image in Flatlist of React Native. Issue is that due to high resolutions images memory limit reached and app get crashed on iPhone. Is there any way i can fetch direct thumb url like image url (e.g. url: 'assets-library://asset/asset.JPG?id=5BECA80C-33B3-46A0-AE44-CF28A838CECF&ext=JPG',) ?

Currently i am using 'React-native-photo-framework'.

like image 513
Nilesh Kikani Avatar asked Nov 08 '22 09:11

Nilesh Kikani


1 Answers

getAssets takes a prepareForSizeDisplay prop. This uses PHCachingImageManager to request images of assets at a specified size.

Example:

RNPhotosFramework.getAssets({
    startIndex: 0,
    endIndex: 100,
    prepareForSizeDisplay: Rect(100,100),
    fetchOptions: {
        sourceTypes: ['userLibrary'],
        sortDescriptors: [{
            key: 'creationDate',
            ascending: true,
        }]
    }
}).then((response) => console.log(response.assets));

When the user taps the row in your FlatList, you can then fetch the full-size asset. Don't fetch the full-size asset until you need to display it.

like image 166
Aaron Brager Avatar answered Nov 15 '22 11:11

Aaron Brager