Skip to content

Commit 24df59e

Browse files
committed
🐳 chore: add example
1 parent e8529d9 commit 24df59e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+9258
-0
lines changed

example/.buckconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2

example/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Windows files
2+
[*.bat]
3+
end_of_line = crlf

example/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};

example/.flowconfig

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore polyfills
9+
node_modules/react-native/Libraries/polyfills/.*
10+
11+
; Flow doesn't support platforms
12+
.*/Libraries/Utilities/LoadingView.js
13+
14+
[untyped]
15+
.*/node_modules/@react-native-community/cli/.*/.*
16+
17+
[include]
18+
19+
[libs]
20+
node_modules/react-native/interface.js
21+
node_modules/react-native/flow/
22+
23+
[options]
24+
emoji=true
25+
26+
exact_by_default=true
27+
28+
format.bracket_spacing=false
29+
30+
module.file_ext=.js
31+
module.file_ext=.json
32+
module.file_ext=.ios.js
33+
34+
munge_underscores=true
35+
36+
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
37+
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
38+
39+
suppress_type=$FlowIssue
40+
suppress_type=$FlowFixMe
41+
suppress_type=$FlowFixMeProps
42+
suppress_type=$FlowFixMeState
43+
44+
[lints]
45+
sketchy-null-number=warn
46+
sketchy-null-mixed=warn
47+
sketchy-number=warn
48+
untyped-type-import=warn
49+
nonstrict-import=warn
50+
deprecated-type=warn
51+
unsafe-getters-setters=warn
52+
unnecessary-invariant=warn
53+
signature-verification-failure=warn
54+
55+
[strict]
56+
deprecated-type
57+
nonstrict-import
58+
sketchy-null
59+
unclear-type
60+
unsafe-getters-setters
61+
untyped-import
62+
untyped-type-import
63+
64+
[version]
65+
^0.158.0

example/.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Windows files should use crlf line endings
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
*.bat text eol=crlf

example/.gitignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
24+
# Android/IntelliJ
25+
#
26+
build/
27+
.idea
28+
.gradle
29+
local.properties
30+
*.iml
31+
*.hprof
32+
33+
# node.js
34+
#
35+
node_modules/
36+
npm-debug.log
37+
yarn-error.log
38+
39+
# BUCK
40+
buck-out/
41+
\.buckd/
42+
*.keystore
43+
!debug.keystore
44+
45+
# fastlane
46+
#
47+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
48+
# screenshots whenever they are needed.
49+
# For more information about the recommended setup visit:
50+
# https://docs.fastlane.tools/best-practices/source-control/
51+
52+
*/fastlane/report.xml
53+
*/fastlane/Preview.html
54+
*/fastlane/screenshots
55+
56+
# Bundle artifact
57+
*.jsbundle
58+
59+
# CocoaPods
60+
/ios/Pods/

example/.prettierignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# OS
2+
.DS_Store
3+
.idea
4+
.editorconfig
5+
.npmrc
6+
package-lock.json
7+
yarn.lock
8+
node_modules/
9+
android/
10+
ios/
11+
12+
# Ignored suffix
13+
*.log
14+
*.svg
15+
*.png
16+
*ignore

example/.prettierrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
printWidth: 120,
3+
tabWidth: 2,
4+
useTabs: false,
5+
semi: true,
6+
singleQuote: true,
7+
quoteProps: 'as-needed',
8+
jsxSingleQuote: false,
9+
trailingComma: 'all',
10+
bracketSpacing: true,
11+
jsxBracketSameLine: false,
12+
arrowParens: 'always',
13+
rangeStart: 0,
14+
rangeEnd: Infinity,
15+
requirePragma: false,
16+
insertPragma: false,
17+
proseWrap: 'preserve',
18+
htmlWhitespaceSensitivity: 'css',
19+
endOfLine: 'lf',
20+
embeddedLanguageFormatting: 'auto',
21+
};

example/.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

example/App.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import React, { useState, useEffect, useRef } from 'react';
2+
import { SafeAreaView, StyleSheet, Platform, View, ScrollView, Text, Button } from 'react-native';
3+
import RNSimpleOpenvpn, { addVpnStateListener, removeVpnStateListener } from 'react-native-simple-openvpn';
4+
5+
const isIPhone = Platform.OS === 'ios';
6+
const PRIMARY_COLOR = 'skyblue';
7+
8+
const App = () => {
9+
const [log, setLog] = useState('');
10+
const logScrollView = useRef(null);
11+
12+
useEffect(() => {
13+
async function observeVpn() {
14+
if (isIPhone) {
15+
await RNSimpleOpenvpn.observeState();
16+
}
17+
18+
addVpnStateListener((e) => {
19+
updateLog(JSON.stringify(e), undefined, 2);
20+
});
21+
}
22+
23+
observeVpn();
24+
25+
return async () => {
26+
if (isIPhone) {
27+
await RNSimpleOpenvpn.stopObserveState();
28+
}
29+
30+
removeVpnStateListener();
31+
};
32+
});
33+
34+
async function startOvpn() {
35+
try {
36+
await RNSimpleOpenvpn.connect({
37+
remoteAddress: '',
38+
ovpnFileName: 'Japan', // Japan or Russian (android assets folder)
39+
assetsPath: '',
40+
providerBundleIdentifier: 'com.your.network.extension.bundle.id',
41+
localizedDescription: 'TestRNSimpleOvpn',
42+
});
43+
} catch (error) {
44+
updateLog(error);
45+
}
46+
}
47+
48+
async function stopOvpn() {
49+
try {
50+
await RNSimpleOpenvpn.disconnect();
51+
} catch (error) {
52+
updateLog(error);
53+
}
54+
}
55+
56+
function printVpnState() {
57+
updateLog(JSON.stringify(RNSimpleOpenvpn.VpnState, undefined, 2));
58+
}
59+
60+
function updateLog(newLog) {
61+
const now = new Date().toLocaleTimeString();
62+
setLog(`${log}\n[${now}] ${newLog}`);
63+
}
64+
65+
return (
66+
<SafeAreaView style={styles.container}>
67+
<View style={styles.btnContainer}>
68+
<Button title="Connect" color={PRIMARY_COLOR} onPress={startOvpn} />
69+
<Button title="Disconnect" color={PRIMARY_COLOR} onPress={stopOvpn} />
70+
<Button title="Vpn State" color={PRIMARY_COLOR} onPress={printVpnState} />
71+
<Button title="Clean Log" color={PRIMARY_COLOR} onPress={() => setLog('')} />
72+
</View>
73+
<View style={styles.logContainer}>
74+
<ScrollView
75+
ref={logScrollView}
76+
style={styles.logScroll}
77+
onContentSizeChange={() => logScrollView.current.scrollToEnd({ animted: true })}
78+
>
79+
<Text>{log}</Text>
80+
</ScrollView>
81+
</View>
82+
</SafeAreaView>
83+
);
84+
};
85+
86+
const styles = StyleSheet.create({
87+
container: {
88+
flex: 1,
89+
paddingTop: '20%',
90+
alignItems: 'center',
91+
},
92+
btnContainer: {
93+
width: '80%',
94+
height: '25%',
95+
justifyContent: 'space-between',
96+
},
97+
logContainer: {
98+
width: '80%',
99+
height: '50%',
100+
borderColor: PRIMARY_COLOR,
101+
borderWidth: 2,
102+
marginTop: 10,
103+
padding: 10,
104+
},
105+
logScroll: {
106+
flex: 1,
107+
},
108+
});
109+
110+
export default App;

0 commit comments

Comments
 (0)