1- import React , { Component } from 'react' ;
1+ import React , { Component } from 'react'
22import {
33 StyleSheet ,
44 WebView ,
55 Platform
6- } from 'react-native' ;
6+ } from 'react-native'
77
8- import { readdir , copyFileAssets , MainBundlePath , DocumentDirectoryPath } from 'react-native-fs' ;
9- import { unzip , subscribe } from 'react-native-zip-archive' ;
8+ import { readdir , copyFileAssets , MainBundlePath , DocumentDirectoryPath } from 'react-native-fs'
9+ import { unzip , subscribe } from 'react-native-zip-archive'
1010
1111export default class App extends Component {
1212 constructor ( ) {
13- super ( ) ;
13+ super ( )
1414 this . state = {
1515 uri : 'https://github.com/plrthink/react-native-zip-archive'
1616 }
1717 }
1818
1919 componentWillMount ( ) {
2020 this . zipProgress = subscribe ( ( progress , filePath ) => {
21- console . log ( progress , filePath ) ;
22- } ) ;
21+ console . log ( progress , filePath )
22+ } )
2323 }
2424
2525 componentDidMount ( ) {
26- let sourcePath ;
27- const targetPath = DocumentDirectoryPath ;
26+ let sourcePath
27+ const targetPath = DocumentDirectoryPath
2828
2929 if ( Platform . OS === 'android' ) {
3030 // since I can't simply get absolute path of files in assets folder,
3131 // I am copying the file from assets folder to document folder as a workaround.
32- sourcePath = `${ DocumentDirectoryPath } /static.zip` ;
32+ sourcePath = `${ DocumentDirectoryPath } /static.zip`
3333
3434 copyFileAssets ( 'static.zip' , sourcePath )
35- . then ( ( ) => {
36- return readdir ( DocumentDirectoryPath ) ;
37- } )
38- . then ( ( result ) => {
39- return unzip ( sourcePath , DocumentDirectoryPath ) ;
40- } )
41- . then ( ( path ) => {
42- console . log ( `unzip file to ${ path } ` ) ;
43- this . setState ( {
44- uri : `file://${ path } /static/index.html`
45- } ) ;
46- } )
47- . catch ( ( error ) => {
48- console . log ( error ) ;
49- } )
35+ . then ( ( ) => {
36+ return readdir ( DocumentDirectoryPath )
37+ } )
38+ . then ( ( result ) => {
39+ return unzip ( sourcePath , DocumentDirectoryPath )
40+ } )
41+ . then ( ( path ) => {
42+ console . log ( `unzip file to ${ path } ` )
43+ this . setState ( {
44+ uri : `file://${ path } /static/index.html`
45+ } )
46+ } )
47+ . catch ( ( error ) => {
48+ console . log ( error )
49+ } )
5050 } else {
51- sourcePath = `${ MainBundlePath } /static.zip` ;
51+ sourcePath = `${ MainBundlePath } /static.zip`
5252
5353 unzip ( sourcePath , targetPath )
5454 . then ( ( path ) => {
55- console . log ( `unzip file to ${ path } ` ) ;
55+ console . log ( `unzip file to ${ path } ` )
5656 this . setState ( {
5757 uri : `${ path } /static/index.html`
58- } ) ;
58+ } )
5959 } )
6060 . catch ( ( error ) => {
61- console . log ( error ) ;
62- } ) ;
61+ console . log ( error )
62+ } )
6363 }
6464 }
6565
6666 componentWillUnmount ( ) {
67- this . zipProgress . remove ( ) ;
67+ this . zipProgress . remove ( )
6868 }
6969
70- render ( ) {
70+ render ( ) {
7171 const { uri } = this . state
7272
7373 console . log ( uri )
@@ -79,13 +79,13 @@ export default class App extends Component {
7979 startInLoadingState = { true }
8080 scalesPageToFit = { true }
8181 />
82- ) ;
82+ )
8383 }
8484}
8585
8686const styles = StyleSheet . create ( {
8787 webView : {
8888 flex : 1 ,
89- marginTop : 20 ,
90- } ,
91- } ) ;
89+ marginTop : 20
90+ }
91+ } )
0 commit comments