1
- import React , { useState } from 'react' ;
1
+ import React , { useState } from 'react'
2
2
import {
3
+ Platform ,
3
4
SafeAreaView ,
4
5
ScrollView ,
5
6
StatusBar ,
6
7
StyleSheet ,
7
8
Text ,
8
9
TextInput ,
9
10
TouchableOpacity ,
10
- View ,
11
11
useColorScheme ,
12
- Platform ,
13
- } from 'react-native' ;
14
-
15
- import SandboxReactNativeView from 'react-native-multinstance' ;
16
-
12
+ View ,
13
+ } from 'react-native'
17
14
// File system imports
18
- import RNFS from 'react-native-fs' ;
15
+ import RNFS from 'react-native-fs'
16
+ import SandboxReactNativeView from 'react-native-multinstance'
19
17
20
- const SHARED_FILE_PATH = `${ RNFS . DocumentDirectoryPath } /shared_test_file.txt` ;
18
+ const SHARED_FILE_PATH = `${ RNFS . DocumentDirectoryPath } /shared_test_file.txt`
21
19
22
20
function App ( ) : React . JSX . Element {
23
- const isDarkMode = useColorScheme ( ) === 'dark' ;
24
- const [ textContent , setTextContent ] = useState < string > ( '' ) ;
25
- const [ status , setStatus ] = useState < string > ( 'Ready' ) ;
21
+ const isDarkMode = useColorScheme ( ) === 'dark'
22
+ const [ textContent , setTextContent ] = useState < string > ( '' )
23
+ const [ status , setStatus ] = useState < string > ( 'Ready' )
26
24
27
25
const theme = {
28
26
background : isDarkMode ? '#000000' : '#ffffff' ,
@@ -34,78 +32,85 @@ function App(): React.JSX.Element {
34
32
border : isDarkMode ? '#38383a' : '#c6c6c8' ,
35
33
success : '#34c759' ,
36
34
error : '#ff3b30' ,
37
- } ;
35
+ }
38
36
39
37
const writeFile = async ( ) => {
40
38
try {
41
- setStatus ( 'Writing file...' ) ;
42
- await RNFS . writeFile ( SHARED_FILE_PATH , textContent , 'utf8' ) ;
43
- setStatus ( `Successfully wrote: "${ textContent } "` ) ;
39
+ setStatus ( 'Writing file...' )
40
+ await RNFS . writeFile ( SHARED_FILE_PATH , textContent , 'utf8' )
41
+ setStatus ( `Successfully wrote: "${ textContent } "` )
44
42
} catch ( error ) {
45
- setStatus ( `Write error: ${ ( error as Error ) . message } ` ) ;
43
+ setStatus ( `Write error: ${ ( error as Error ) . message } ` )
46
44
}
47
- } ;
45
+ }
48
46
49
47
const readFile = async ( ) => {
50
48
try {
51
- setStatus ( 'Reading file...' ) ;
52
- const content = await RNFS . readFile ( SHARED_FILE_PATH , 'utf8' ) ;
53
- setTextContent ( content ) ;
54
- setStatus ( `Successfully read: "${ content } "` ) ;
49
+ setStatus ( 'Reading file...' )
50
+ const content = await RNFS . readFile ( SHARED_FILE_PATH , 'utf8' )
51
+ setTextContent ( content )
52
+ setStatus ( `Successfully read: "${ content } "` )
55
53
} catch ( error ) {
56
- setStatus ( `Read error: ${ ( error as Error ) . message } ` ) ;
54
+ setStatus ( `Read error: ${ ( error as Error ) . message } ` )
57
55
}
58
- } ;
56
+ }
59
57
60
58
const getStatusStyle = ( ) => {
61
59
if ( status . includes ( 'error' ) ) {
62
- return { color : theme . error } ;
60
+ return { color : theme . error }
63
61
}
64
62
if ( status . includes ( 'Successfully' ) ) {
65
- return { color : theme . success } ;
63
+ return { color : theme . success }
66
64
}
67
- return { color : theme . textSecondary } ;
68
- } ;
65
+ return { color : theme . textSecondary }
66
+ }
69
67
70
68
return (
71
- < SafeAreaView style = { [ styles . container , { backgroundColor : theme . background } ] } >
69
+ < SafeAreaView
70
+ style = { [ styles . container , { backgroundColor : theme . background } ] } >
72
71
< StatusBar
73
72
barStyle = { isDarkMode ? 'light-content' : 'dark-content' }
74
73
backgroundColor = { theme . background }
75
74
/>
76
75
< ScrollView
77
76
contentInsetAdjustmentBehavior = "automatic"
78
- style = { { backgroundColor : theme . background } }
77
+ style = { { backgroundColor : theme . background } }
79
78
showsVerticalScrollIndicator = { false } >
80
-
81
79
{ /* Header */ }
82
- < View style = { [ styles . header , { backgroundColor : theme . surface } ] } >
83
- < Text style = { [ styles . headerTitle , { color : theme . text } ] } >
80
+ < View style = { [ styles . header , { backgroundColor : theme . surface } ] } >
81
+ < Text style = { [ styles . headerTitle , { color : theme . text } ] } >
84
82
File System Sandbox Demo
85
83
</ Text >
86
- < Text style = { [ styles . headerSubtitle , { color : theme . textSecondary } ] } >
84
+ < Text style = { [ styles . headerSubtitle , { color : theme . textSecondary } ] } >
87
85
Multi-instance file system access testing
88
86
</ Text >
89
87
</ View >
90
88
91
89
< View style = { styles . content } >
92
90
{ /* Host Application Section */ }
93
- < View style = { [ styles . card , { backgroundColor : theme . surface , borderColor : theme . border } ] } >
91
+ < View
92
+ style = { [
93
+ styles . card ,
94
+ { backgroundColor : theme . surface , borderColor : theme . border } ,
95
+ ] } >
94
96
< View style = { styles . cardHeader } >
95
- < Text style = { [ styles . cardTitle , { color : theme . text } ] } >
97
+ < Text style = { [ styles . cardTitle , { color : theme . text } ] } >
96
98
Host Application
97
99
</ Text >
98
- < View style = { [ styles . badge , { backgroundColor : theme . primary } ] } >
100
+ < View style = { [ styles . badge , { backgroundColor : theme . primary } ] } >
99
101
< Text style = { styles . badgeText } > Primary</ Text >
100
102
</ View >
101
103
</ View >
102
104
103
105
< TextInput
104
- style = { [ styles . textInput , {
105
- color : theme . text ,
106
- backgroundColor : theme . background ,
107
- borderColor : theme . border ,
108
- } ] }
106
+ style = { [
107
+ styles . textInput ,
108
+ {
109
+ color : theme . text ,
110
+ backgroundColor : theme . background ,
111
+ borderColor : theme . border ,
112
+ } ,
113
+ ] }
109
114
value = { textContent }
110
115
onChangeText = { setTextContent }
111
116
placeholder = "Enter text to write to file..."
@@ -115,80 +120,108 @@ function App(): React.JSX.Element {
115
120
116
121
< View style = { styles . buttonGroup } >
117
122
< TouchableOpacity
118
- style = { [ styles . button , styles . primaryButton , { backgroundColor : theme . primary } ] }
123
+ style = { [
124
+ styles . button ,
125
+ styles . primaryButton ,
126
+ { backgroundColor : theme . primary } ,
127
+ ] }
119
128
onPress = { writeFile } >
120
129
< Text style = { styles . buttonText } > Write File</ Text >
121
130
</ TouchableOpacity >
122
131
123
132
< TouchableOpacity
124
- style = { [ styles . button , styles . secondaryButton , { backgroundColor : theme . secondary } ] }
133
+ style = { [
134
+ styles . button ,
135
+ styles . secondaryButton ,
136
+ { backgroundColor : theme . secondary } ,
137
+ ] }
125
138
onPress = { readFile } >
126
139
< Text style = { styles . buttonText } > Read File</ Text >
127
140
</ TouchableOpacity >
128
141
</ View >
129
142
130
- < View style = { [ styles . statusContainer , { backgroundColor : theme . background } ] } >
131
- < Text style = { [ styles . statusLabel , { color : theme . textSecondary } ] } > Status:</ Text >
143
+ < View
144
+ style = { [
145
+ styles . statusContainer ,
146
+ { backgroundColor : theme . background } ,
147
+ ] } >
148
+ < Text style = { [ styles . statusLabel , { color : theme . textSecondary } ] } >
149
+ Status:
150
+ </ Text >
132
151
< Text style = { [ styles . statusText , getStatusStyle ( ) ] } >
133
152
{ status }
134
153
</ Text >
135
154
</ View >
136
155
137
- < Text style = { [ styles . pathText , { color : theme . textSecondary } ] } >
156
+ < Text style = { [ styles . pathText , { color : theme . textSecondary } ] } >
138
157
{ SHARED_FILE_PATH }
139
158
</ Text >
140
159
</ View >
141
160
142
161
{ /* Sandbox Sections */ }
143
- < View style = { [ styles . card , { backgroundColor : theme . surface , borderColor : theme . border } ] } >
162
+ < View
163
+ style = { [
164
+ styles . card ,
165
+ { backgroundColor : theme . surface , borderColor : theme . border } ,
166
+ ] } >
144
167
< View style = { styles . cardHeader } >
145
- < Text style = { [ styles . cardTitle , { color : theme . text } ] } >
168
+ < Text style = { [ styles . cardTitle , { color : theme . text } ] } >
146
169
Sandbox: react-native-fs
147
170
</ Text >
148
171
< View style = { [ styles . badge , styles . sandboxBadge ] } >
149
172
< Text style = { styles . badgeText } > Sandbox</ Text >
150
173
</ View >
151
174
</ View >
152
175
< SandboxReactNativeView
153
- style = { [ styles . sandbox , { backgroundColor : theme . background , borderColor : theme . border } ] }
176
+ style = { [
177
+ styles . sandbox ,
178
+ { backgroundColor : theme . background , borderColor : theme . border } ,
179
+ ] }
154
180
moduleName = { 'AppFS' }
155
181
jsBundleSource = "sandbox-fs"
156
182
allowedTurboModules = { [ 'RNFSManager' , 'FileReaderModule' ] }
157
183
onMessage = { message => {
158
- console . log ( 'Host received message from sandbox:' , message ) ;
184
+ console . log ( 'Host received message from sandbox:' , message )
159
185
} }
160
186
onError = { error => {
161
- console . log ( 'Host received error from sandbox:' , error ) ;
187
+ console . log ( 'Host received error from sandbox:' , error )
162
188
} }
163
189
/>
164
190
</ View >
165
191
166
- < View style = { [ styles . card , { backgroundColor : theme . surface , borderColor : theme . border } ] } >
192
+ < View
193
+ style = { [
194
+ styles . card ,
195
+ { backgroundColor : theme . surface , borderColor : theme . border } ,
196
+ ] } >
167
197
< View style = { styles . cardHeader } >
168
- < Text style = { [ styles . cardTitle , { color : theme . text } ] } >
198
+ < Text style = { [ styles . cardTitle , { color : theme . text } ] } >
169
199
Sandbox: react-native-file-access
170
200
</ Text >
171
201
< View style = { [ styles . badge , styles . sandboxBadge ] } >
172
202
< Text style = { styles . badgeText } > Sandbox</ Text >
173
203
</ View >
174
204
</ View >
175
205
< SandboxReactNativeView
176
- style = { [ styles . sandbox , { backgroundColor : theme . background , borderColor : theme . border } ] }
206
+ style = { [
207
+ styles . sandbox ,
208
+ { backgroundColor : theme . background , borderColor : theme . border } ,
209
+ ] }
177
210
moduleName = { 'AppFileAccess' }
178
211
allowedTurboModules = { [ 'FileAccess' ] }
179
212
jsBundleSource = "sandbox-file-access"
180
213
onMessage = { message => {
181
- console . log ( 'Host received message from sandbox:' , message ) ;
214
+ console . log ( 'Host received message from sandbox:' , message )
182
215
} }
183
216
onError = { error => {
184
- console . log ( 'Host received error from sandbox:' , error ) ;
217
+ console . log ( 'Host received error from sandbox:' , error )
185
218
} }
186
219
/>
187
220
</ View >
188
221
</ View >
189
222
</ ScrollView >
190
223
</ SafeAreaView >
191
- ) ;
224
+ )
192
225
}
193
226
194
227
const styles = StyleSheet . create ( {
@@ -201,7 +234,7 @@ const styles = StyleSheet.create({
201
234
...Platform . select ( {
202
235
ios : {
203
236
shadowColor : '#000' ,
204
- shadowOffset : { width : 0 , height : 1 } ,
237
+ shadowOffset : { width : 0 , height : 1 } ,
205
238
shadowOpacity : 0.1 ,
206
239
shadowRadius : 4 ,
207
240
} ,
@@ -231,7 +264,7 @@ const styles = StyleSheet.create({
231
264
...Platform . select ( {
232
265
ios : {
233
266
shadowColor : '#000' ,
234
- shadowOffset : { width : 0 , height : 2 } ,
267
+ shadowOffset : { width : 0 , height : 2 } ,
235
268
shadowOpacity : 0.1 ,
236
269
shadowRadius : 8 ,
237
270
} ,
@@ -325,6 +358,6 @@ const styles = StyleSheet.create({
325
358
borderWidth : 1 ,
326
359
borderRadius : 8 ,
327
360
} ,
328
- } ) ;
361
+ } )
329
362
330
- export default App ;
363
+ export default App
0 commit comments