From c6396b65b62585e7c12fee694a78d6537bffdf6e Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Mon, 22 Aug 2022 23:19:42 +1200 Subject: [PATCH] Quit trying to convert to rnfs --- DrawerMenu.tsx | 6 ++-- android/app/build.gradle | 1 + android/app/src/main/AndroidManifest.xml | 1 + .../main/java/com/massive/MainApplication.kt | 2 +- android/settings.gradle | 2 ++ file.ts | 18 +++-------- package.json | 2 +- yarn.lock | 32 +++++++++++++++---- 8 files changed, 39 insertions(+), 25 deletions(-) diff --git a/DrawerMenu.tsx b/DrawerMenu.tsx index c5c6d6b..7b2f10a 100644 --- a/DrawerMenu.tsx +++ b/DrawerMenu.tsx @@ -2,7 +2,7 @@ import {NavigationProp, useNavigation} from '@react-navigation/native'; import React, {useCallback, useContext, useState} from 'react'; import {ToastAndroid} from 'react-native'; import DocumentPicker from 'react-native-document-picker'; -import {FileSystem} from 'react-native-file-access'; +import RNFS from 'react-native-fs'; import {Divider, IconButton, Menu} from 'react-native-paper'; import {DatabaseContext, DrawerParamList} from './App'; import ConfirmDialog from './ConfirmDialog'; @@ -54,7 +54,7 @@ export default function DrawerMenu({name}: {name: keyof DrawerParamList}) { const uploadSets = useCallback(async () => { const result = await DocumentPicker.pickSingle(); - const file = await FileSystem.readFile(result.uri); + const file = await RNFS.readFile(result.uri); console.log(`${DrawerMenu.name}.${uploadSets.name}:`, file.length); const lines = file.split('\n'); if (lines[0] != setFields) @@ -76,7 +76,7 @@ export default function DrawerMenu({name}: {name: keyof DrawerParamList}) { const uploadPlans = useCallback(async () => { const result = await DocumentPicker.pickSingle(); - const file = await FileSystem.readFile(result.uri); + const file = await RNFS.readFile(result.uri); console.log(`${DrawerMenu.name}.uploadPlans:`, file.length); const lines = file.split('\n'); if (lines[0] != planFields) diff --git a/android/app/build.gradle b/android/app/build.gradle index 2a9efaa..90568da 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -165,6 +165,7 @@ dependencies { implementation "androidx.core:core-ktx:1.8.0" implementation project(':react-native-sqlite-storage') implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" + implementation project(':react-native-fs') debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { exclude group:'com.facebook.fbjni' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 0b340a7..aebcd32 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -16,6 +16,7 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/AppTheme" + android:requestLegacyExternalStorage="true" android:dataExtractionRules="@xml/data_extraction_rules"> { - const filePath = `${Dirs.DocumentDir}/${name}`; - const permission = async () => { - const granted = await PermissionsAndroid.request( - PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, - ); - return granted === PermissionsAndroid.RESULTS.GRANTED; - }; - const granted = await permission(); - if (!granted) return; - await FileSystem.writeFile(filePath, data); - if (!FileSystem.exists(filePath)) return; - await FileSystem.cpExternal(filePath, name, 'downloads'); + const filePath = `${RNFS.DownloadDirectoryPath}/${name}`; + await RNFS.writeFile(filePath, data); ToastAndroid.show(`Saved "${name}". Check downloads`, ToastAndroid.LONG); }; diff --git a/package.json b/package.json index e4711c8..826e4c4 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "react-devtools": "^4.24.7", "react-native": "0.69.1", "react-native-document-picker": "^8.1.1", - "react-native-file-access": "^2.4.3", + "react-native-fs": "^2.20.0", "react-native-gesture-handler": "^2.5.0", "react-native-linear-gradient": "^2.6.2", "react-native-pager-view": "^5.4.24", diff --git a/yarn.lock b/yarn.lock index ca49011..0f64cc0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3511,6 +3511,13 @@ __metadata: languageName: node linkType: hard +"base-64@npm:^0.1.0": + version: 0.1.0 + resolution: "base-64@npm:0.1.0" + checksum: 5a42938f82372ab5392cbacc85a5a78115cbbd9dbef9f7540fa47d78763a3a8bd7d598475f0d92341f66285afd377509851a9bb5c67bbecb89686e9255d5b3eb + languageName: node + linkType: hard + "base64-js@npm:^1.1.2, base64-js@npm:^1.3.1, base64-js@npm:^1.5.1": version: 1.5.1 resolution: "base64-js@npm:1.5.1" @@ -8017,7 +8024,7 @@ __metadata: react-devtools: ^4.24.7 react-native: 0.69.1 react-native-document-picker: ^8.1.1 - react-native-file-access: ^2.4.3 + react-native-fs: ^2.20.0 react-native-gesture-handler: ^2.5.0 react-native-linear-gradient: ^2.6.2 react-native-pager-view: ^5.4.24 @@ -9627,13 +9634,19 @@ __metadata: languageName: node linkType: hard -"react-native-file-access@npm:^2.4.3": - version: 2.4.3 - resolution: "react-native-file-access@npm:2.4.3" +"react-native-fs@npm:^2.20.0": + version: 2.20.0 + resolution: "react-native-fs@npm:2.20.0" + dependencies: + base-64: ^0.1.0 + utf8: ^3.0.0 peerDependencies: - react: "*" react-native: "*" - checksum: 5fc11fedad93f188b4edb9c4a4b4e9e7bb80e06fb6b61da97ae0946ab7ab0bd3eaf448263a696669461b6e2a030e76fcd26b755c2e21c494e90dd71f647375a6 + react-native-windows: "*" + peerDependenciesMeta: + react-native-windows: + optional: true + checksum: 0be9bb9a5c13b501d0a3006efc3aa5c0b5b211456ee04718297f4e522532f3527f1daa220bd67d3b82d819ed8fdab8f64b7d6e0d7b768c1fd1d8ec9122d94316 languageName: node linkType: hard @@ -11677,6 +11690,13 @@ __metadata: languageName: node linkType: hard +"utf8@npm:^3.0.0": + version: 3.0.0 + resolution: "utf8@npm:3.0.0" + checksum: cb89a69ad9ab393e3eae9b25305b3ff08bebca9adc839191a34f90777eb2942f86a96369d2839925fea58f8f722f7e27031d697f10f5f39690f8c5047303e62d + languageName: node + linkType: hard + "util-deprecate@npm:^1.0.1, util-deprecate@npm:~1.0.1": version: 1.0.2 resolution: "util-deprecate@npm:1.0.2"