Thanks for reading, I am trying to save remote GIF to system album in React Native in iOS.
I have try the following ways but all of them making GIFs as static images.
I create a new React Native project of 0.62.2 to run these code
"dependencies": {"@react-native-community/cameraroll": "^1.7.2","react": "16.11.0","react-native": "0.62.2","react-native-fs": "^2.16.6","rn-fetch-blob": "^0.12.0" }
- Save GIF directly by CameraRoll.
Not working because https://github.com/react-native-community/react-native-cameraroll/issues/16
const uri = 'https://i.loli.net/2020/05/28/YKaCdO1pexuThbN.gif'CameraRoll.saveToCameraRoll(uri);
- Download GIF firstly by react-native-fs
const img = 'https://i.loli.net/2020/05/28/YKaCdO1pexuThbN.gif'const storeLocation = `${RNFS.TemporaryDirectoryPath}`;const pathName = `${new Date().getTime()}_babycam_moji.gif`;const downloadPath = `${storeLocation}${pathName}`;const ret = RNFS.downloadFile({ fromUrl: img, toFile: downloadPath,});ret.promise.then((res) => { console.log('res', res); if (res && res.statusCode === 200) { const promise = CameraRoll.saveToCameraRoll( `file://${downloadPath}`, ); promise.then(() => {}); } else { }});
- download GIF firstly by rn-fetch-blob
RNFetchBlob.config({appendExt: 'gif', fileCache: true}) .fetch('GET', img) .then((res) => { console.log('res', res.path()); CameraRoll.saveToCameraRoll(res.path());});
How can I save GIFs to album in iOS in react-native?
Thanks