Skip to content

Commit 18413a5

Browse files
authored
Merge pull request #10 from ExodusMovement/@cawfree/bundle-support
Add asset bundle support
2 parents da0b426 + 400bffe commit 18413a5

72 files changed

Lines changed: 9598 additions & 92 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.

android/src/main/java/com/rnthreads/RNFileReaderPackage.java

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

android/src/main/java/com/rnthreads/RNThreadModule.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,13 @@ public void startThread(final String jsFileName, final Promise promise) {
7777
: createReleaseBundleLoader(jsFileName, jsFileSlug);
7878

7979
try {
80-
ArrayList<ReactPackage> threadPackages = new ArrayList<ReactPackage>(Arrays.asList(additionalThreadPackages));
81-
threadPackages.add(0, new ThreadBaseReactPackage(getReactInstanceManager()));
80+
ArrayList<ReactPackage> threadPackages = new ArrayList<ReactPackage>();
81+
// react-native-threads
82+
threadPackages.add(new ThreadBaseReactPackage(getReactInstanceManager()));
83+
// react native runtime
84+
threadPackages.addAll(getReactInstanceManager().getPackages());
85+
// thread-specific native modules
86+
threadPackages.addAll(Arrays.asList(additionalThreadPackages));
8287

8388
ReactContextBuilder threadContextBuilder = new ReactContextBuilder(getReactApplicationContext())
8489
.setJSBundleLoader(bundleLoader)
@@ -204,7 +209,7 @@ private JSBundleLoader createDevBundleLoader(String jsFileName, String jsFileSlu
204209

205210
private JSBundleLoader createReleaseBundleLoader(String jsFileName, String jsFileSlug) {
206211
Log.d(TAG, "createReleaseBundleLoader - reading file from assets");
207-
return JSBundleLoader.createAssetLoader(reactApplicationContext, "assets://threads/" + jsFileSlug + ".bundle", false);
212+
return JSBundleLoader.createAssetLoader(reactApplicationContext, "assets://" + jsFileSlug + ".jsbundle", false);
208213
}
209214

210215
private ReactInstanceManager getReactInstanceManager() {

android/src/main/java/com/rnthreads/RNThreadPackage.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,14 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212

13-
import com.rnthreads.RNFileReaderPackage;
14-
1513
public class RNThreadPackage implements ReactPackage {
1614

1715
private ReactNativeHost reactNativeHost;
1816
private ReactPackage additionalThreadPackages[];
1917

2018
public RNThreadPackage(ReactNativeHost pReactNativeHost, ReactPackage ...pAdditionalThreadPackages) {
2119
this.reactNativeHost = pReactNativeHost;
22-
23-
// You can add more packages here if you find that using some
24-
// vanilla RN functionality leaves the background thread unable
25-
// to mount properly.
26-
ReactPackage[] extraPackages = {
27-
new RNFileReaderPackage() /* https://github.com/facebook/react-native/blob/7ea7d946c643f076c29bcf11b927f7569e3c516f/Libraries/Core/setUpXHR.js#L31 */
28-
// ...
29-
};
30-
31-
// Create an array large enough to acommodate for both
32-
// the user-defined `pAdditionalThreadPackages` and the
33-
// `extraPackages`:
34-
this.additionalThreadPackages = new ReactPackage[pAdditionalThreadPackages.length + extraPackages.length];
35-
36-
// i.e. [...pAdditionalThreadPackages, ...extraPackages];
37-
System.arraycopy(pAdditionalThreadPackages, 0, this.additionalThreadPackages, 0, pAdditionalThreadPackages.length);
38-
System.arraycopy(extraPackages, 0, this.additionalThreadPackages, pAdditionalThreadPackages.length, extraPackages.length);
20+
this.additionalThreadPackages = pAdditionalThreadPackages;
3921
}
4022

4123
@Override
@@ -49,4 +31,4 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
4931
new RNThreadModule(reactContext, reactNativeHost, additionalThreadPackages)
5032
);
5133
}
52-
}
34+
}

android/src/main/java/com/rnthreads/ThreadBaseReactPackage.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,7 @@ public ThreadBaseReactPackage(ReactInstanceManager reactInstanceManager) {
3030

3131
@Override
3232
public List<NativeModule> createNativeModules(ReactApplicationContext catalystApplicationContext) {
33-
return Arrays.<NativeModule>asList(
34-
// Core list
35-
new AndroidInfoModule(catalystApplicationContext),
36-
new ExceptionsManagerModule(reactInstanceManager.getDevSupportManager()),
37-
new AppStateModule(catalystApplicationContext),
38-
new TimingModule(catalystApplicationContext, reactInstanceManager.getDevSupportManager()),
39-
new UIManagerStubModule(catalystApplicationContext),
40-
new SourceCodeModule(catalystApplicationContext),
41-
new JSCHeapCapture(catalystApplicationContext),
42-
43-
// Main list
44-
new IntentModule(catalystApplicationContext),
45-
new NetworkingModule(catalystApplicationContext),
46-
new VibrationModule(catalystApplicationContext),
47-
new WebSocketModule(catalystApplicationContext),
48-
new ThreadSelfModule(catalystApplicationContext)
49-
);
33+
return Arrays.<NativeModule>asList(new ThreadSelfModule(catalystApplicationContext));
5034
}
5135

5236
@Override

android/src/main/java/com/rnthreads/UIManagerStubModule.java

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

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/.gitignore

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
ios/.xcode.env.local
24+
25+
# Android/IntelliJ
26+
#
27+
build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.iml
32+
*.hprof
33+
.cxx/
34+
*.keystore
35+
!debug.keystore
36+
37+
# node.js
38+
#
39+
node_modules/
40+
npm-debug.log
41+
yarn-error.log
42+
43+
# fastlane
44+
#
45+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
46+
# screenshots whenever they are needed.
47+
# For more information about the recommended setup visit:
48+
# https://docs.fastlane.tools/best-practices/source-control/
49+
50+
**/fastlane/report.xml
51+
**/fastlane/Preview.html
52+
**/fastlane/screenshots
53+
**/fastlane/test_output
54+
55+
# Bundle artifact
56+
*.jsbundle
57+
58+
# Ruby / CocoaPods
59+
/ios/Pods/
60+
/vendor/bundle/
61+
.bundle
62+
63+
# Temporary files created by Metro to check the health of the file watcher
64+
.metro-health-check*

example/.node-version

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

example/.prettierrc.js

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

example/.watchmanconfig

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

0 commit comments

Comments
 (0)