Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Expose static asset dir to client.js
Browse files Browse the repository at this point in the history
Summary: While testing publishing apps, it occurred to me that users of the default starter project need to rewrite the background path as well as the asset root if they change the static assets location. To avoid this, I'd like to rewrite the starter project to use this new method, which references the assetRoot set at init time. That allows there to be one point of configuration for all properly-referenced assets on both the runtime and the React sides.

Reviewed By: mikearmstrong001

Differential Revision: D7822165

fbshipit-source-id: c16a55f5a82df4440fcbc893c4eb050fa86a280f
  • Loading branch information
andrewimm authored and facebook-github-bot committed May 2, 2018
1 parent f67599b commit 0b971cd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions React360/js/ReactInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type React360Options = {
* native platform capabilities.
*/
export default class ReactInstance {
_assetRoot: string;
_audioModule: ?AudioModule;
_cameraPosition: Vec3;
_cameraQuat: Quaternion;
Expand Down Expand Up @@ -140,6 +141,7 @@ export default class ReactInstance {
if (!assetRoot.endsWith('/')) {
assetRoot += '/';
}
this._assetRoot = assetRoot;
const runtimeOptions = {
assetRoot: assetRoot,
customViews: options.customViews || [],
Expand Down Expand Up @@ -441,4 +443,12 @@ export default class ReactInstance {
this._eventLayer.style.height = `${height}px`;
this.compositor.resizeCanvas(width, height);
}

/**
* Transforms the local path of a static asset to include the current static
* asset directory.
*/
getAssetURL(localPath: string): string {
return this._assetRoot + localPath;
}
}

0 comments on commit 0b971cd

Please sign in to comment.