Skip to content

Commit 500aae2

Browse files
committed
1. tweak code to meet lint rules
2. fix wrong export expressions
1 parent 45e6ba6 commit 500aae2

File tree

13 files changed

+211
-94
lines changed

13 files changed

+211
-94
lines changed

.eslintrc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"extends": "standard"
3-
}
2+
"extends": [
3+
"standard",
4+
"plugin:react/recommended"
5+
],
6+
"plugins": ["jest"],
7+
"env": {
8+
"jest/globals": true
9+
}
10+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ unzipAssets(assetPath, targetPath)
8484
})
8585
```
8686

87-
**subscribe(callback: ({ progress: number })): EmitterSubscription**
87+
**subscribe(callback: ({ progress: number, filePath: string })): EmitterSubscription**
8888

8989
> Subscribe to the progress callbacks. Useful for displaying a progress bar on your UI during the process.
9090

example/App.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
1-
import React, { Component } from 'react';
1+
import React, { Component } from 'react'
22
import {
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

1111
export 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

8686
const styles = StyleSheet.create({
8787
webView: {
8888
flex: 1,
89-
marginTop: 20,
90-
},
91-
});
89+
marginTop: 20
90+
}
91+
})

example/__tests__/index.android.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import 'react-native';
2-
import React from 'react';
3-
import Index from '../index.android.js';
1+
import 'react-native'
2+
import React from 'react'
3+
import Index from '../index.android.js'
44

55
// Note: test renderer must be required after react-native.
6-
import renderer from 'react-test-renderer';
6+
import renderer from 'react-test-renderer'
77

88
it('renders correctly', () => {
9-
const tree = renderer.create(
9+
renderer.create(
1010
<Index />
11-
);
12-
});
11+
)
12+
})

example/__tests__/index.ios.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import 'react-native';
2-
import React from 'react';
3-
import Index from '../index.ios.js';
1+
import 'react-native'
2+
import React from 'react'
3+
import Index from '../index.ios.js'
44

55
// Note: test renderer must be required after react-native.
6-
import renderer from 'react-test-renderer';
6+
import renderer from 'react-test-renderer'
77

88
it('renders correctly', () => {
9-
const tree = renderer.create(
9+
renderer.create(
1010
<Index />
11-
);
12-
});
11+
)
12+
})

example/index.android.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44
* @flow
55
*/
66

7-
import React, { Component } from 'react';
7+
import React, { Component } from 'react'
88
import {
99
AppRegistry,
1010
StyleSheet,
1111
View
12-
} from 'react-native';
13-
import App from './App';
12+
} from 'react-native'
13+
import App from './App'
1414

1515
export default class example extends Component {
16-
render() {
16+
render () {
1717
return (
1818
<View style={styles.container}>
1919
<App />
2020
</View>
21-
);
21+
)
2222
}
2323
}
2424

2525
const styles = StyleSheet.create({
2626
container: {
2727
flex: 1,
28-
alignItems: 'stretch',
28+
alignItems: 'stretch'
2929
}
30-
});
30+
})
3131

32-
AppRegistry.registerComponent('example', () => example);
32+
AppRegistry.registerComponent('example', () => example)

example/index.ios.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44
* @flow
55
*/
66

7-
import React, { Component } from 'react';
7+
import React, { Component } from 'react'
88
import {
99
AppRegistry,
1010
StyleSheet,
1111
View
12-
} from 'react-native';
13-
import App from './App';
12+
} from 'react-native'
13+
import App from './App'
1414

1515
export default class example extends Component {
16-
render() {
16+
render () {
1717
return (
1818
<View style={styles.container}>
1919
<App />
2020
</View>
21-
);
21+
)
2222
}
2323
}
2424

2525
const styles = StyleSheet.create({
2626
container: {
2727
flex: 1,
28-
alignItems: 'stretch',
28+
alignItems: 'stretch'
2929
}
30-
});
30+
})
3131

32-
AppRegistry.registerComponent('example', () => example);
32+
AppRegistry.registerComponent('example', () => example)

example/ios/example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
4040
ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADBDB9271DFEBF0700ED6528 /* libRCTBlob.a */; };
4141
C4AB69018C47413FAE720AFB /* libRNZipArchive.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBF63E7468094A26BD064EB4 /* libRNZipArchive.a */; };
42-
D0041C0E1F7802E300FCB9AE /* static.zip in Resources */ = {isa = PBXBuildFile; fileRef = D0041C0D1F7802E200FCB9AE /* static.zip */; };
42+
D0E1771A1FF8F0B00096B24F /* static.zip in Resources */ = {isa = PBXBuildFile; fileRef = D0E177191FF8F0B00096B24F /* static.zip */; };
4343
D919C929006A412D9F34DCF8 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1E7BB616B8493A8EB27F72 /* libz.tbd */; };
4444
/* End PBXBuildFile section */
4545

@@ -326,7 +326,7 @@
326326
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
327327
ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = "<group>"; };
328328
C9834F59091B4342849896AE /* libRNFS.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNFS.a; sourceTree = "<group>"; };
329-
D0041C0D1F7802E200FCB9AE /* static.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = static.zip; sourceTree = "<group>"; };
329+
D0E177191FF8F0B00096B24F /* static.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; name = static.zip; path = ../static.zip; sourceTree = "<group>"; };
330330
D3FE826C603F45CC8A7D0711 /* RNFS.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNFS.xcodeproj; path = "../node_modules/react-native-fs/RNFS.xcodeproj"; sourceTree = "<group>"; };
331331
EBF63E7468094A26BD064EB4 /* libRNZipArchive.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNZipArchive.a; sourceTree = "<group>"; };
332332
FD1E7BB616B8493A8EB27F72 /* libz.tbd */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
@@ -469,7 +469,7 @@
469469
13B07FAE1A68108700A75B9A /* example */ = {
470470
isa = PBXGroup;
471471
children = (
472-
D0041C0D1F7802E200FCB9AE /* static.zip */,
472+
D0E177191FF8F0B00096B24F /* static.zip */,
473473
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
474474
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
475475
13B07FB01A68108700A75B9A /* AppDelegate.m */,
@@ -1051,7 +1051,7 @@
10511051
isa = PBXResourcesBuildPhase;
10521052
buildActionMask = 2147483647;
10531053
files = (
1054-
D0041C0E1F7802E300FCB9AE /* static.zip in Resources */,
1054+
D0E1771A1FF8F0B00096B24F /* static.zip in Resources */,
10551055
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
10561056
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
10571057
);

example/ios/static.zip

-621 Bytes
Binary file not shown.

index.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,23 @@ const {
99

1010
const RNZipArchive = NativeModules.RNZipArchive
1111

12-
const ZipArchive = {
13-
unzip (source, target) {
14-
return RNZipArchive.unzip(source, target)
15-
},
16-
zip (source, target) {
17-
return RNZipArchive.zip(source, target)
18-
},
19-
unzipAssets (source, target) {
20-
if (!RNZipArchive.unzipAssets) {
21-
throw new Error('unzipAssets not supported on this platform')
22-
}
12+
export const unzip = (source, target) => {
13+
return RNZipArchive.unzip(source, target)
14+
}
15+
export const zip = (source, target) => {
16+
return RNZipArchive.zip(source, target)
17+
}
2318

24-
return RNZipArchive.unzipAssets(source, target)
25-
},
26-
subscribe (callback) {
27-
var emitter = Platform.OS === 'ios' ? NativeAppEventEmitter : DeviceEventEmitter
28-
return emitter.addListener('zipArchiveProgressEvent', callback)
19+
export const unzipAssets = (source, target) => {
20+
if (!RNZipArchive.unzipAssets) {
21+
throw new Error('unzipAssets not supported on this platform')
2922
}
23+
24+
return RNZipArchive.unzipAssets(source, target)
3025
}
3126

32-
export default ZipArchive
27+
export const subscribe = callback => {
28+
const emitter =
29+
Platform.OS === 'ios' ? NativeAppEventEmitter : DeviceEventEmitter
30+
return emitter.addListener('zipArchiveProgressEvent', callback)
31+
}

0 commit comments

Comments
 (0)