This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
88 lines (76 loc) · 2.05 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import {
Button,
NativeEventEmitter,
NativeModules,
SafeAreaView,
ScrollView,
StatusBar,
Text,
} from 'react-native';
import {selectDirectory} from 'react-native-directory-picker';
import {useGetAndroidPermissions} from './use-get-android-permissions';
const App = () => {
const [msg, setMsg] = React.useState('Before the update');
const [directory, setDirectory] = React.useState('');
const [bytes, setBytes] = React.useState([0]);
useGetAndroidPermissions();
React.useEffect(() => {
if (!directory) {
return;
}
NativeModules.HelloModule.observeFile(directory)
.then(() => {
setMsg('Ready to read file');
})
.catch(err => setMsg('ERROR: ' + err));
const eventEmitter = new NativeEventEmitter(NativeModules.HelloModule);
const eventListener = eventEmitter.addListener(
'ReadChange',
(event: {
bytes: number[],
currentFileChunkIndex: number,
fileSize: number,
}) => {
setBytes(event.bytes);
},
);
return () => {
eventListener.remove();
NativeModules.HelloModule.stopObservingFile();
};
}, [directory]);
const pickDirectory = () => {
selectDirectory()
.then(async directory => {
setDirectory(directory);
setMsg('Ready get directory data file');
})
.catch(err => {
setMsg('ERROR: ' + err);
});
};
const goUp = () => {
NativeModules.HelloModule.goUp();
};
const goDown = () => {
NativeModules.HelloModule.goDown();
};
return (
<SafeAreaView>
<StatusBar />
<ScrollView contentInsetAdjustmentBehavior="automatic">
<Button title={'Pick Directory'} onPress={pickDirectory} />
<Text>{msg}</Text>
<Button title={'Go up'} onPress={goUp} />
<Button title={'Go down'} onPress={goDown} />
<ScrollView>
{bytes.map((byte, index) => (
<Text key={index}>{byte}</Text>
))}
</ScrollView>
</ScrollView>
</SafeAreaView>
);
};
export default App;