Compare commits

...

1 Commits
master ... rnfs

Author SHA1 Message Date
Brandon Presley c6396b65b6 Quit trying to convert to rnfs 2022-08-22 23:19:42 +12:00
8 changed files with 39 additions and 25 deletions

View File

@ -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)

View File

@ -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'

View File

@ -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">
<meta-data
android:name="com.dieam.reactnativepushnotification.notification_foreground"

View File

@ -69,4 +69,4 @@ class MainApplication : Application(), ReactApplication {
}
}
}
}
}

View File

@ -4,6 +4,8 @@ include ':app'
includeBuild('../node_modules/react-native-gradle-plugin')
include ':react-native-sqlite-storage'
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/platforms/android')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android')
if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
include(":ReactAndroid")

18
file.ts
View File

@ -1,18 +1,8 @@
import {PermissionsAndroid, ToastAndroid} from 'react-native';
import {Dirs, FileSystem} from 'react-native-file-access';
import {ToastAndroid} from 'react-native';
import RNFS from 'react-native-fs';
export const write = async (name: string, data: string) => {
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);
};

View File

@ -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",

View File

@ -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"