Skip to content

Commit 72aead3

Browse files
committed
init
0 parents  commit 72aead3

113 files changed

Lines changed: 21626 additions & 0 deletions

File tree

Some content is hidden

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

.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

.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+
};

.flowconfig

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 unexpected extra "@providesModule"
9+
.*/node_modules/.*/node_modules/fbjs/.*
10+
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+
node_modules/react-native/Libraries/react-native/React.js
15+
16+
; Ignore polyfills
17+
node_modules/react-native/Libraries/polyfills/.*
18+
19+
; These should not be required directly
20+
; require from fbjs/lib instead: require('fbjs/lib/warning')
21+
node_modules/warning/.*
22+
23+
; Flow doesn't support platforms
24+
.*/Libraries/Utilities/HMRLoadingView.js
25+
26+
[untyped]
27+
.*/node_modules/@react-native-community/cli/.*/.*
28+
29+
[include]
30+
31+
[libs]
32+
node_modules/react-native/Libraries/react-native/react-native-interface.js
33+
node_modules/react-native/flow/
34+
35+
[options]
36+
emoji=true
37+
38+
esproposal.optional_chaining=enable
39+
esproposal.nullish_coalescing=enable
40+
41+
module.file_ext=.js
42+
module.file_ext=.json
43+
module.file_ext=.ios.js
44+
45+
module.system=haste
46+
module.system.haste.use_name_reducers=true
47+
# get basename
48+
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
49+
# strip .js or .js.flow suffix
50+
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
51+
# strip .ios suffix
52+
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
53+
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
54+
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
55+
module.system.haste.paths.blacklist=.*/__tests__/.*
56+
module.system.haste.paths.blacklist=.*/__mocks__/.*
57+
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
58+
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/RNTester/.*
59+
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/IntegrationTests/.*
60+
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/react-native/react-native-implementation.js
61+
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
62+
63+
munge_underscores=true
64+
65+
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'
66+
67+
suppress_type=$FlowIssue
68+
suppress_type=$FlowFixMe
69+
suppress_type=$FlowFixMeProps
70+
suppress_type=$FlowFixMeState
71+
72+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
73+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
74+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
75+
76+
[lints]
77+
sketchy-null-number=warn
78+
sketchy-null-mixed=warn
79+
sketchy-number=warn
80+
untyped-type-import=warn
81+
nonstrict-import=warn
82+
deprecated-type=warn
83+
unsafe-getters-setters=warn
84+
inexact-spread=warn
85+
unnecessary-invariant=warn
86+
signature-verification-failure=warn
87+
deprecated-utility=error
88+
89+
[strict]
90+
deprecated-type
91+
nonstrict-import
92+
sketchy-null
93+
unclear-type
94+
unsafe-getters-setters
95+
untyped-import
96+
untyped-type-import
97+
98+
[version]
99+
^0.98.0

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
project.xcworkspace
24+
25+
# Android/IntelliJ
26+
#
27+
build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.iml
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+
44+
# fastlane
45+
#
46+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47+
# screenshots whenever they are needed.
48+
# For more information about the recommended setup visit:
49+
# https://docs.fastlane.tools/best-practices/source-control/
50+
51+
*/fastlane/report.xml
52+
*/fastlane/Preview.html
53+
*/fastlane/screenshots
54+
55+
# Bundle artifact
56+
*.jsbundle
57+
58+
# CocoaPods
59+
/ios/Pods/

.watchmanconfig

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

Approach.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
## Approach 1:
2+
3+
> pph-app-rewards-lib (js)
4+
>> pph-app-base-lib (js) -- include UI components, API client, Local storage and Security storage
5+
6+
(Maybe also need some native lib if necessary)
7+
8+
**Why we need the base lib ?**
9+
10+
1. Rewards dose not just include UI code, it also sends request.
11+
12+
2. pph-app-rewards-lib should not directly include all the *api request*, *local storage* code.
13+
14+
3. If we export rewards to HiSG, we also need to use the same way to integrate rewards.
15+
16+
> ps: for the pph-app-base-lib can also be used in other pph apps (eo)
17+
18+
19+
## Approach 2: split js bundle
20+
21+
1. Demo
22+
23+
2. Mechanism
24+
25+
2.1 What‘s inside js bundle
26+
```js
27+
var __BUNDLE_START_TIME__=...
28+
...
29+
__d(function(...){},123,[]);
30+
...
31+
__d(function(a,s,t,e,n,r,u){n.exports={name:"statusbar",displayName:"statusbar"}},484,[]);
32+
__r(82);
33+
__r(0);
34+
```
35+
36+
2.2 What's the number used for (how __d function works)
37+
```js
38+
__d = function (r, i, n) {
39+
if (null != e[i]) return;
40+
var o = {
41+
dependencyMap: n,
42+
factory: r,
43+
hasError: !1,
44+
importedAll: t,
45+
importedDefault: t,
46+
isInitialized: !1,
47+
publicModule: { exports: {} }
48+
};
49+
e[i] = o
50+
}
51+
```
52+
> So the number is a global identifier for js module, but the number is random generated, if we need to split the js bundle we need to fix the id
53+
54+
`metro/src/lib/createModuleIdFactory.js`
55+
```js
56+
'use strict';
57+
58+
function createModuleIdFactory(): (path: string) => number {
59+
const fileToIdMap: Map<string, number> = new Map();
60+
let nextId = 0;
61+
return (path: string) => {
62+
let id = fileToIdMap.get(path);
63+
if (typeof id !== 'number') {
64+
id = nextId++;
65+
fileToIdMap.set(path, id);
66+
}
67+
return id;
68+
};
69+
}
70+
71+
module.exports = createModuleIdFactory;
72+
```
73+
74+
2.3 Metro(react-native packaging tool) provide a way to customize the id generation.
75+
76+
`metro.config.js` metro config file in the root dir of react-native project
77+
78+
```js
79+
const createModuleIdFactory = require('./config/createModuleIdFactory');
80+
module.exports = {
81+
transformer: {
82+
getTransformOptions: async () => ({
83+
transform: {
84+
experimentalImportSupport: false,
85+
inlineRequires: false,
86+
},
87+
}),
88+
},
89+
serializer: {
90+
createModuleIdFactory: createModuleIdFactory
91+
}
92+
};
93+
```
94+
95+
```js
96+
'use strict';
97+
const path = require('path');
98+
const pathSep = path.posix.sep;
99+
100+
function createModuleIdFactory() {
101+
const fileToIdMap = new Map();
102+
const projectRootPath = `${process.cwd()}`;
103+
return (path) => {
104+
let moduleName = '';
105+
if (path.indexOf(`node_modules${pathSep}react-native${pathSep}Libraries${pathSep}`) > 0) {
106+
moduleName = path.substr(path.lastIndexOf(pathSep) + 1);
107+
} else if (path.indexOf(projectRootPath) === 0) {
108+
moduleName = path.substr(projectRootPath.length + 1);
109+
}
110+
moduleName = moduleName.replace('.js', '');
111+
moduleName = moduleName.replace('.png', '');
112+
let regExp = pathSep === '\\' ? new RegExp('\\\\', 'gm') : new RegExp(pathSep, 'gm');
113+
moduleName = moduleName.replace(regExp, '_');
114+
return moduleName;
115+
};
116+
}
117+
118+
module.exports = createModuleIdFactory;
119+
```
120+
121+
```js
122+
...
123+
__d(
124+
function (g, r, i, a, m, e, d) {
125+
var t = r(d[0]);
126+
Object.defineProperty(e, "__esModule", { value: !0 }), e.default = void 0;
127+
var o = t(r(d[1])), u = r(d[2]), n = u.StyleSheet.create({ image: { height: 24 } });
128+
e.default = function (t) {
129+
var c = t.routeName, l = t.focused, f = { Home: r(l ? d[3] : d[4]), My: r(l ? d[5] : d[6]) };
130+
return o.default.createElement(u.Image, { style: n.image, source: f[c], resizeMode: "contain" })
131+
}
132+
},
133+
"src_components_TabBarIcon_index",
134+
[
135+
"node_modules_@babel_runtime_helpers_interopRequireDefault",
136+
"node_modules_react_index",
137+
"react-native-implementation",
138+
"src_assets_icons_home_fill",
139+
"src_assets_icons_home",
140+
"src_assets_icons_my_fill",
141+
"src_assets_icons_my"
142+
]
143+
);
144+
...
145+
```
146+
147+
2.3 split jsbundle to base.bundle/app1.bundle/app2.bundle ...
148+
149+
```
150+
react-native bundle --platform ios --dev false --entry-file base.js --bundle-output build/ios/common.jsbundle --assets-dest build/ios/
151+
152+
react-native bundle --platform ios --dev false --entry-file index.js --bundle-output build/ios/main_app_all.jsbundle --assets-dest build/ios/
153+
154+
react-native bundle --platform ios --dev false --entry-file rewards/index.js --bundle-output build/ios/sub_app_all.jsbundle --assets-dest build/ios/
155+
156+
node diff.js ./build/ios/common.jsbundle ./build/ios/main_app_all.jsbundle ./build/ios/main_app.jsbundle
157+
node diff.js ./build/ios/common.jsbundle ./build/ios/sub_app_all.jsbundle ./build/ios/sub_app.jsbundle
158+
```
159+
160+
2.4 Native cod
161+

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### split js bundle
2+
3+
react-native bundle --platform ios --dev false --entry-file base.js --bundle-output build/ios/common.jsbundle --assets-dest build/ios/
4+
5+
react-native bundle --platform ios --dev false --entry-file index.js --bundle-output build/ios/main_app_all.jsbundle --assets-dest build/ios/
6+
7+
react-native bundle --platform ios --dev false --entry-file rewards/index.js --bundle-output build/ios/sub_app_all.jsbundle --assets-dest build/ios/
8+
9+
node diff.js ./build/ios/common.jsbundle ./build/ios/main_app_all.jsbundle ./build/ios/main_app.jsbundle
10+
node diff.js ./build/ios/common.jsbundle ./build/ios/sub_app_all.jsbundle ./build/ios/sub_app.jsbundle
11+

__tests__/App-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @format
3+
*/
4+
5+
import 'react-native';
6+
import React from 'react';
7+
import App from '../App';
8+
9+
// Note: test renderer must be required after react-native.
10+
import renderer from 'react-test-renderer';
11+
12+
it('renders correctly', () => {
13+
renderer.create(<App />);
14+
});

0 commit comments

Comments
 (0)