From 1d3c006b97a53cb7aba6afe2866722fe7d3e5798 Mon Sep 17 00:00:00 2001 From: Amit Uttam Date: Thu, 5 Mar 2020 13:23:39 -0300 Subject: [PATCH] MM-23014 Keep Android cache for vector icons (#4011) --- app/utils/file.js | 18 ++++++++++--- patches/react-native-vector-icons+6.6.0.patch | 25 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 patches/react-native-vector-icons+6.6.0.patch diff --git a/app/utils/file.js b/app/utils/file.js index 5e2db1692..52247ba08 100644 --- a/app/utils/file.js +++ b/app/utils/file.js @@ -55,7 +55,8 @@ export function generateId() { return 'uid' + id; } -const dirsToExclude = ['Cache.db', 'WebKit', 'WebView']; +const vectorIconsDir = 'vectorIcons'; +const dirsToExclude = ['Cache.db', 'WebKit', 'WebView', vectorIconsDir]; async function getDirectorySize(fileStats) { if (fileStats?.length) { const total = await fileStats.reduce(async (previousPromise, stat) => { @@ -93,8 +94,19 @@ export async function deleteFileCache() { const isCacheDir = await RNFetchBlob.fs.isDir(cacheDir); if (isCacheDir) { try { - await RNFetchBlob.fs.unlink(cacheDir); - await RNFetchBlob.fs.mkdir(cacheDir); + if (Platform.OS === 'ios') { + await RNFetchBlob.fs.unlink(cacheDir); + await RNFetchBlob.fs.mkdir(cacheDir); + } else { + const cacheStats = await RNFetchBlob.fs.lstat(RNFetchBlob.fs.dirs.CacheDir); + if (cacheStats?.length) { + cacheStats.forEach((stat) => { + if (!stat.path.includes(vectorIconsDir)) { + RNFetchBlob.fs.unlink(stat.path); + } + }); + } + } } catch (e) { // do nothing } diff --git a/patches/react-native-vector-icons+6.6.0.patch b/patches/react-native-vector-icons+6.6.0.patch new file mode 100644 index 000000000..799d792d3 --- /dev/null +++ b/patches/react-native-vector-icons+6.6.0.patch @@ -0,0 +1,25 @@ +diff --git a/node_modules/react-native-vector-icons/android/src/main/java/com/oblador/vectoricons/VectorIconsModule.java b/node_modules/react-native-vector-icons/android/src/main/java/com/oblador/vectoricons/VectorIconsModule.java +index ddb740c..3738367 100755 +--- a/node_modules/react-native-vector-icons/android/src/main/java/com/oblador/vectoricons/VectorIconsModule.java ++++ b/node_modules/react-native-vector-icons/android/src/main/java/com/oblador/vectoricons/VectorIconsModule.java +@@ -43,7 +43,8 @@ public class VectorIconsModule extends ReactContextBaseJavaModule { + public void getImageForFont(String fontFamily, String glyph, Integer fontSize, Integer color, Callback callback) { + Context context = getReactApplicationContext(); + File cacheFolder = context.getCacheDir(); +- String cacheFolderPath = cacheFolder.getAbsolutePath() + "/"; ++ String cacheFolderPath = cacheFolder.getAbsolutePath() + "/vectorIcons/"; ++ File vectorIconsFolder = new File(cacheFolderPath); + + float scale = context.getResources().getDisplayMetrics().density; + String scaleSuffix = "@" + (scale == (int) scale ? Integer.toString((int) scale) : Float.toString(scale)) + "x"; +@@ -54,6 +55,10 @@ public class VectorIconsModule extends ReactContextBaseJavaModule { + String cacheFileUrl = "file://" + cacheFilePath; + File cacheFile = new File(cacheFilePath); + ++ if (!vectorIconsFolder.exists()) { ++ vectorIconsFolder.mkdirs(); ++ } ++ + if(cacheFile.exists()) { + callback.invoke(null, cacheFileUrl); + } else {