Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow developers to load JavaScript bundle from any source.
Summary: This patch adds two pieces of functionality: - Exposes `JSBundleLoader` to allow a developer to load JavaScript bundles as they choose. - Adds `ReactBridge.loadScripFromFile` method which loads a JavaScript bundle from an arbitrary file path. Example usage: ``` JSBundleLoader jsBundleLoader = new JSBundleLoader() { Override public void loadScript(ReactBridge reactBridge) { reactBridge.loadScriptFromFile("/sdcard/Download/index.android.bundle"); } }; mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setJSBundleLoader(jsBundleLoader) .setJSMainModuleName("") /* necessary due to TODO(6803830) */ .addPackage(new MainReactPackage()) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); ``` cc ide Closes #3189 Reviewed By: svcscm Differential Revision: D2535819 Pulled By: mkonicek fb-gh-sync-id: f319299dbe29bab3b7e91f94249c14b270d9fec3
- Loading branch information
Showing
5 changed files
with
65 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news for Android developers!
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🎈
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!!!
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supports ios ?
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sailei1 - this was already possible on ios
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @benvinegar
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setJSBundleLoader no method
android gradle compile version 0.16.0
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Richard-Cao It's called
setJSBundleFile
and it takes a string (the file path) as argument.3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but how to use custom
JSBundleLoader
? @satya1643a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Richard-Cao You need to write code to manage bundle updates. Your code can download the bundle file and you can give the download path to
setJSBundleFile
.I'm using a custom bundle manager - https://github.com/scrollback/io.scrollback.neighborhoods/blob/master/android/app/src/main/java/io/scrollback/neighborhoods/MainActivity.java#L44
https://github.com/scrollback/io.scrollback.neighborhoods/blob/master/android/app/src/main/java/io/scrollback/neighborhoods/bundle/JSBundleManager.java
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I will try @satya164
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://facebook.github.io/react-native/docs/embedded-app-android.html#sharing-a-reactinstance-across-multiple-activities-fragments-in-your-app
this suggest have a singleton "holder" that holds a
ReactInstanceManager
but your code if want to download bundle, when Activity init,
ReactInstanceManager
not a singletonhow @satya164
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Richard-Cao You can write another singleton class which just uses a single instance of the bundlemanager.
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @satya164
3a743ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just what I was waiting for!