44 * @flow
55 */
66
7- import React , { Component } from 'react' ;
8- import {
9- Platform ,
10- StyleSheet ,
11- Text ,
12- View ,
13- TouchableOpacity
14- } from 'react-native' ;
7+ import React , { Component } from 'react' ;
8+ import { Platform , StyleSheet , Text , View , TouchableOpacity } from 'react-native' ;
159
16- import RNFileSelector from 'react-native-file-selector'
10+ import RNFileSelector from 'react-native-file-selector' ;
1711
18- import RNFS from 'react-native-fs'
12+ import RNFS from 'react-native-fs' ;
1913
20- import animatedPhoto from './assets/animated_photo.gif'
21- import photo from './assets/photo.jpg'
14+ import animatedPhoto from './assets/animated_photo.gif' ;
15+ import photo from './assets/photo.jpg' ;
2216// import info from './assets/nfo.plist'
2317
2418export default class App extends Component < Props > {
25- constructor ( props ) {
26- super ( props )
19+ constructor ( props ) {
20+ super ( props ) ;
2721
2822 this . state = {
29- visible : false
30- }
23+ visible : false ,
24+ } ;
3125 }
3226
33- _onPress ( ) {
27+ _onPress ( ) {
3428 let filter ;
3529 if ( Platform . OS === 'ios' ) {
3630 filter = [ ] ;
3731 } else if ( Platform . OS === 'android' ) {
38- filter = " .*\\.*" ;
32+ filter = ' .*\\.*' ;
3933 }
4034
41-
42- RNFileSelector . Show (
43- {
44- path : RNFS . DocumentDirectoryPath ,
45- filter : filter ,
46- title : 'Select File' ,
47- closeMenu : true ,
48- editable : true ,
49- onDone : ( path ) => {
50- console . log ( 'file selected: ' + path )
51- } ,
52- onCancel : ( ) => {
53- console . log ( 'cancelled' )
54- }
55- }
56- )
35+ RNFileSelector . Show ( {
36+ path : RNFS . DocumentDirectoryPath ,
37+ filter : filter ,
38+ title : 'Select File' ,
39+ closeMenu : true ,
40+ editable : true ,
41+ onDone : path => {
42+ console . log ( 'file selected: ' + path ) ;
43+ } ,
44+ onCancel : ( ) => {
45+ console . log ( 'cancelled' ) ;
46+ } ,
47+ } ) ;
5748 }
5849
59- componentDidMount ( ) {
60-
50+ componentDidMount ( ) {
6151 // create a path you want to write to
62- let animatedPhotoPath = RNFS . DocumentDirectoryPath + " /animated_photo.gif" ;
63- let photoPath = RNFS . DocumentDirectoryPath + " /photo.jpg" ;
52+ let animatedPhotoPath = RNFS . DocumentDirectoryPath + ' /animated_photo.gif' ;
53+ let photoPath = RNFS . DocumentDirectoryPath + ' /photo.jpg' ;
6454 // let infoPath = RNFS.DocumentDirectoryPath + "/info.plist";
65- let assetsPath = RNFS . DocumentDirectoryPath + '/assets'
55+ let assetsPath = RNFS . DocumentDirectoryPath + '/assets' ;
6656
6757 // write the file
68- RNFS . writeFile ( animatedPhotoPath , animatedPhoto , " utf8" )
58+ RNFS . writeFile ( animatedPhotoPath , animatedPhoto , ' utf8' )
6959 . then ( success => {
70- console . log ( " FILE WRITTEN!" ) ;
60+ console . log ( ' FILE WRITTEN!' ) ;
7161 } )
7262 . catch ( err => {
7363 console . log ( err . message ) ;
7464 } ) ;
7565
76- RNFS . writeFile ( photoPath , photo , " utf8" )
66+ RNFS . writeFile ( photoPath , photo , ' utf8' )
7767 . then ( success => {
78- console . log ( " FILE WRITTEN!" ) ;
68+ console . log ( ' FILE WRITTEN!' ) ;
7969 } )
8070 . catch ( err => {
8171 console . log ( err . message ) ;
8272 } ) ;
8373
84-
85- RNFS . mkdir ( assetsPath )
86- . then ( success => {
87- console . log ( 'DIRECTORY CREATED' )
88-
89- RNFS . writeFile ( assetsPath + "/animated_photo.gif" , animatedPhoto , "utf8" )
90- . then ( success => {
91- console . log ( "DIRECTORY WRITTEN!" ) ;
92- } )
93- . catch ( err => {
94- console . log ( err . message ) ;
95- } ) ;
96-
97- RNFS . writeFile ( assetsPath + "/photo.jpg" , photo , "utf8" )
98- . then ( success => {
99- console . log ( "DIRECTORY WRITTEN!" ) ;
100- } )
101- . catch ( err => {
102- console . log ( err . message ) ;
103- } ) ;
104- } )
105-
106-
107- // RNFS.writeFile(infoPath, info, "utf8")
74+ RNFS . mkdir ( assetsPath ) . then ( success => {
75+ console . log ( 'DIRECTORY CREATED' ) ;
76+
77+ RNFS . writeFile ( assetsPath + '/animated_photo.gif' , animatedPhoto , 'utf8' )
78+ . then ( success => {
79+ console . log ( 'DIRECTORY WRITTEN!' ) ;
80+ } )
81+ . catch ( err => {
82+ console . log ( err . message ) ;
83+ } ) ;
84+
85+ RNFS . writeFile ( assetsPath + '/photo.jpg' , photo , 'utf8' )
86+ . then ( success => {
87+ console . log ( 'DIRECTORY WRITTEN!' ) ;
88+ } )
89+ . catch ( err => {
90+ console . log ( err . message ) ;
91+ } ) ;
92+ } ) ;
93+
94+ // RNFS.writeFile(infoPath, info, "utf8")
10895 // .then(success => {
10996 // console.log("FILE WRITTEN!");
11097 // })
@@ -114,20 +101,28 @@ export default class App extends Component<Props> {
114101 }
115102
116103 render ( ) {
117- return < View style = { styles . container } >
118- < TouchableOpacity onPress = { ( ) => {
119- this . _onPress ( )
104+ return (
105+ < View style = { styles . container } >
106+ < TouchableOpacity
107+ onPress = { ( ) => {
108+ this . _onPress ( ) ;
120109
121110 // this.setState({ visible: true });
122111 } } >
123112 < Text > Click</ Text >
124- < RNFileSelector title = { "Select File" } visible = { this . state . visible } onDone = { ( path ) => {
125- console . log ( "file selected: " + path ) ;
126- } } onCancel = { ( ) => {
127- console . log ( "cancelled" ) ;
128- } } />
113+ < RNFileSelector
114+ title = { 'Select File' }
115+ visible = { this . state . visible }
116+ onDone = { path => {
117+ console . log ( 'file selected: ' + path ) ;
118+ } }
119+ onCancel = { ( ) => {
120+ console . log ( 'cancelled' ) ;
121+ } }
122+ />
129123 </ TouchableOpacity >
130- < / V i e w > ;
124+ < / V i e w >
125+ ) ;
131126 }
132127}
133128
@@ -137,5 +132,5 @@ const styles = StyleSheet.create({
137132 justifyContent : 'center' ,
138133 alignItems : 'center' ,
139134 backgroundColor : '#F5FCFF' ,
140- }
135+ } ,
141136} ) ;
0 commit comments