Skip to content

Commit c7b712f

Browse files
authored
Merge pull request #89 from smellman/dev-reactnative0.62
React Native 0.62 supports
2 parents 32e3702 + ee160c7 commit c7b712f

File tree

77 files changed

+11631
-10466
lines changed

Some content is hidden

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

77 files changed

+11631
-10466
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ buck-out/
4949

5050
my-release-key.keystore
5151
StaticServerExample/my-release-key.keystore
52+
53+
# Android
54+
.classpath
55+
.project
56+
.settings/
57+
android/.project

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ A cross platform component for serving static assets with React Native.
99

1010
### Installation
1111

12+
From react-native 0.60 autolinking will take care of the link step but don't forget to run pod install
13+
1214
`$ react-native link react-native-static-server`
1315

1416
## Usage

StaticServerExample/.flowconfig

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
; Ignore "BUCK" generated dirs
66
<PROJECT_ROOT>/\.buckd/
77

8-
; Ignore unexpected extra "@providesModule"
9-
.*/node_modules/.*/node_modules/fbjs/.*
8+
; Ignore polyfills
9+
node_modules/react-native/Libraries/polyfills/.*
1010

11-
; Ignore duplicate module providers
12-
; For RN Apps installed via npm, "Libraries" folder is inside
13-
; "node_modules/react-native" but in the source repo it is in the root
14-
.*/Libraries/react-native/React.js
11+
; These should not be required directly
12+
; require from fbjs/lib instead: require('fbjs/lib/warning')
13+
node_modules/warning/.*
1514

16-
; Ignore polyfills
17-
.*/Libraries/polyfills/.*
15+
; Flow doesn't support platforms
16+
.*/Libraries/Utilities/LoadingView.js
1817

19-
; Ignore metro
20-
.*/node_modules/metro/.*
18+
[untyped]
19+
.*/node_modules/@react-native-community/cli/.*/.*
2120

2221
[include]
2322

2423
[libs]
25-
node_modules/react-native/Libraries/react-native/react-native-interface.js
24+
node_modules/react-native/interface.js
2625
node_modules/react-native/flow/
2726

2827
[options]
@@ -31,39 +30,44 @@ emoji=true
3130
esproposal.optional_chaining=enable
3231
esproposal.nullish_coalescing=enable
3332

34-
module.system=haste
35-
module.system.haste.use_name_reducers=true
36-
# get basename
37-
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
38-
# strip .js or .js.flow suffix
39-
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
40-
# strip .ios suffix
41-
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
42-
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
43-
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
44-
module.system.haste.paths.blacklist=.*/__tests__/.*
45-
module.system.haste.paths.blacklist=.*/__mocks__/.*
46-
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
47-
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
33+
module.file_ext=.js
34+
module.file_ext=.json
35+
module.file_ext=.ios.js
4836

4937
munge_underscores=true
5038

51-
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\)$' -> 'RelativeImageStub'
52-
53-
module.file_ext=.js
54-
module.file_ext=.jsx
55-
module.file_ext=.json
56-
module.file_ext=.native.js
39+
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
40+
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'
5741

5842
suppress_type=$FlowIssue
5943
suppress_type=$FlowFixMe
6044
suppress_type=$FlowFixMeProps
6145
suppress_type=$FlowFixMeState
6246

63-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
64-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
65-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
47+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
48+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
6649
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
6750

51+
[lints]
52+
sketchy-null-number=warn
53+
sketchy-null-mixed=warn
54+
sketchy-number=warn
55+
untyped-type-import=warn
56+
nonstrict-import=warn
57+
deprecated-type=warn
58+
unsafe-getters-setters=warn
59+
inexact-spread=warn
60+
unnecessary-invariant=warn
61+
signature-verification-failure=warn
62+
deprecated-utility=error
63+
[strict]
64+
deprecated-type
65+
nonstrict-import
66+
sketchy-null
67+
unclear-type
68+
unsafe-getters-setters
69+
untyped-import
70+
untyped-type-import
71+
6872
[version]
69-
^0.92.0
73+
^0.113.0

StaticServerExample/.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.pbxproj -text
2+
# specific for windows script files
3+
*.bat text eol=crlf

StaticServerExample/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23-
project.xcworkspace
2423

2524
# Android/IntelliJ
2625
#
@@ -40,6 +39,7 @@ yarn-error.log
4039
buck-out/
4140
\.buckd/
4241
*.keystore
42+
!debug.keystore
4343

4444
# fastlane
4545
#
@@ -54,3 +54,6 @@ buck-out/
5454

5555
# Bundle artifact
5656
*.jsbundle
57+
58+
# CocoaPods
59+
/ios/Pods/

StaticServerExample/.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
bracketSpacing: false,
3+
jsxBracketSameLine: true,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
};

StaticServerExample/App.js

Lines changed: 0 additions & 119 deletions
This file was deleted.

StaticServerExample/App.tsx

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* Sample React Native Static Server
3+
* https://github.com/futurepress/react-native-static-server
4+
* @flow
5+
*/
6+
7+
import React, { useState, useEffect } from 'react'
8+
import {
9+
StyleSheet,
10+
Text,
11+
View,
12+
Image
13+
} from 'react-native'
14+
15+
// requires react-native-webview, see: https://github.com/uuidjs/uuid#getrandomvalues-not-supported
16+
import 'react-native-get-random-values'
17+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
18+
import { v4 as uuidv4 } from 'uuid'
19+
import StaticServer from 'react-native-static-server'
20+
import RNFetchBlob from 'rn-fetch-blob'
21+
import { WebView } from 'react-native-webview'
22+
23+
interface ITestViewProps {
24+
port?: number
25+
root?: string
26+
file?: string
27+
target?: any
28+
}
29+
30+
export default function App (props: ITestViewProps): JSX.Element {
31+
const [origin, setOrigin] = useState<string>('')
32+
const [server, setServer] = useState<StaticServer>(null)
33+
const port = typeof props.port !== 'undefined' ? props.port : 3030
34+
const root = typeof props.root !== 'undefined' ? props.root : 'www/'
35+
const file = typeof props.file !== 'undefined' ? props.file : 'index.html'
36+
const target = typeof props.target !== 'undefined' ? props.target : require('./index.html')
37+
38+
useEffect(() => {
39+
if (origin === '') {
40+
// eslint-disable-next-line @typescript-eslint/no-var-requires
41+
const index = target
42+
const { uri } = Image.resolveAssetSource(index)
43+
const path = RNFetchBlob.fs.dirs.DocumentDir + '/' + root
44+
const dest = path + file
45+
const startServer = async (): Promise<void> => {
46+
const newServer = new StaticServer(port, root, { localOnly: true })
47+
const origin = await newServer.start()
48+
setOrigin(origin)
49+
setServer(newServer)
50+
}
51+
const prepare = async (): Promise<void> => {
52+
try {
53+
await RNFetchBlob.fs.mkdir(path)
54+
} catch (e) {
55+
console.log(`directory is created ${path}`)
56+
}
57+
let added: Promise<boolean>
58+
if (uri.includes('file://')) {
59+
// Copy file in release
60+
const result = await RNFetchBlob.fs.exists(dest)
61+
if (!result) {
62+
added = RNFetchBlob.fs.cp(uri, dest)
63+
}
64+
} else {
65+
// Download for development
66+
const result = await RNFetchBlob.config({ fileCache: true }).fetch('GET', uri)
67+
added = RNFetchBlob.fs.mv(result.path(), dest)
68+
}
69+
try {
70+
await added
71+
} catch (e) {
72+
console.log(e)
73+
}
74+
await startServer()
75+
}
76+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
77+
prepare()
78+
return () => {
79+
if (server !== null) {
80+
server.kill()
81+
}
82+
}
83+
}
84+
}, [])
85+
86+
if (origin !== '') {
87+
return <WebView
88+
source={{ uri: `${origin}/${file}` }}
89+
style={styles.webview}
90+
/>
91+
}
92+
return <View style={styles.container}>
93+
<Text>Loading...</Text>
94+
</View>
95+
}
96+
97+
const styles = StyleSheet.create({
98+
container: {
99+
flex: 1,
100+
justifyContent: 'center',
101+
alignItems: 'center',
102+
backgroundColor: '#F5FCFF'
103+
},
104+
webview: {
105+
marginTop: 20,
106+
flex: 1
107+
}
108+
})

0 commit comments

Comments
 (0)