From 0b971cdb1068793c0d01bbe846f9d55ec655084b Mon Sep 17 00:00:00 2001 From: Andrew Imm Date: Tue, 1 May 2018 14:47:01 -0700 Subject: [PATCH] Expose static asset dir to client.js 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 --- React360/js/ReactInstance.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/React360/js/ReactInstance.js b/React360/js/ReactInstance.js index ebe753ffe..a9944d3c0 100755 --- a/React360/js/ReactInstance.js +++ b/React360/js/ReactInstance.js @@ -67,6 +67,7 @@ export type React360Options = { * native platform capabilities. */ export default class ReactInstance { + _assetRoot: string; _audioModule: ?AudioModule; _cameraPosition: Vec3; _cameraQuat: Quaternion; @@ -140,6 +141,7 @@ export default class ReactInstance { if (!assetRoot.endsWith('/')) { assetRoot += '/'; } + this._assetRoot = assetRoot; const runtimeOptions = { assetRoot: assetRoot, customViews: options.customViews || [], @@ -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; + } }