diff --git a/components/AR/ViroARSceneNavigator.tsx b/components/AR/ViroARSceneNavigator.tsx index da8eb37..7c7e7a8 100644 --- a/components/AR/ViroARSceneNavigator.tsx +++ b/components/AR/ViroARSceneNavigator.tsx @@ -30,7 +30,7 @@ import { const ViroARSceneNavigatorModule = NativeModules.VRTARSceneNavigatorModule; -var mathRandomOffset = 0; +let mathRandomOffset = 0; type Props = ViewProps & { /** @@ -76,49 +76,19 @@ type State = { */ export class ViroARSceneNavigator extends React.Component { _component: ViroNativeRef = null; - arSceneNavigator = { - push: this.push, - pop: this.pop, - popN: this.popN, - jump: this.jump, - replace: this.replace, - startVideoRecording: this._startVideoRecording, - stopVideoRecording: this._stopVideoRecording, - takeScreenshot: this._takeScreenshot, - resetARSession: this._resetARSession, - setWorldOrigin: this._setWorldOrigin, - project: this._project, - unproject: this._unproject, - viroAppProps: {} as any, - }; - sceneNavigator = { - push: this.push, - pop: this.pop, - popN: this.popN, - jump: this.jump, - replace: this.replace, - startVideoRecording: this._startVideoRecording, - stopVideoRecording: this._stopVideoRecording, - takeScreenshot: this._takeScreenshot, - resetARSession: this._resetARSession, - setWorldOrigin: this._setWorldOrigin, - project: this._project, - unproject: this._unproject, - viroAppProps: {} as any, - }; constructor(props: Props) { super(props); - var initialSceneTag = this.props.initialSceneKey; + let initialSceneTag = this.props.initialSceneKey; if (initialSceneTag == null) { initialSceneTag = this.getRandomTag(); } - var scene = { + const scene = { sceneClass: this.props.initialScene, tag: initialSceneTag, referenceCount: 1, }; - var sceneDict: ViroSceneDictionary = {}; + const sceneDict: ViroSceneDictionary = {}; sceneDict[scene.tag] = scene; this.state = { sceneDictionary: sceneDict, @@ -127,11 +97,77 @@ export class ViroARSceneNavigator extends React.Component { }; } - getRandomTag() { - var randomTag = Math.random() + mathRandomOffset; + /** + * Starts recording video of the Viro renderer and external audio + * + * @param fileName - name of the file (without extension) + * @param saveToCameraRoll - whether or not the file should also be saved to the camera roll + * @param onError - callback function that accepts an errorCode. + */ + _startVideoRecording = ( + fileName: string, + saveToCameraRoll: boolean, + // TODO: What are the errorCodes? make a type for this + onError: (errorCode: number) => void + ) => { + ViroARSceneNavigatorModule.startVideoRecording( + findNodeHandle(this), + fileName, + saveToCameraRoll, + onError + ); + }; + + /** + * Stops recording the video of the Viro Renderer. + * + * returns Object w/ success, url and errorCode keys. + * @returns Promise that resolves when the video has stopped recording. + */ + _stopVideoRecording = async () => { + return await ViroARSceneNavigatorModule.stopVideoRecording( + findNodeHandle(this) + ); + }; + + /** + * Takes a screenshot of the Viro renderer + * + * @param fileName - name of the file (without extension) + * @param saveToCameraRoll - whether or not the file should also be saved to the camera roll + * returns Object w/ success, url and errorCode keys. + */ + _takeScreenshot = async (fileName: string, saveToCameraRoll: boolean) => { + return await ViroARSceneNavigatorModule.takeScreenshot( + findNodeHandle(this), + fileName, + saveToCameraRoll + ); + }; + + /** + * @todo document _project + * + * @param point + * @returns + */ + async _project(point: Viro3DPoint) { + return await ViroARSceneNavigatorModule.project( + findNodeHandle(this), + point + ); + } + + /** + * Gets a random tag string. + * + * @returns a random tag. + */ + getRandomTag = () => { + const randomTag = Math.random() + mathRandomOffset; mathRandomOffset++; return randomTag.toString(); - } + }; /** * Pushes a scene and reference it with the given key if provided. @@ -145,11 +181,12 @@ export class ViroARSceneNavigator extends React.Component { * push ("sceneKey", scene); * push (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - push(param1?: ViroScene | string, param2?: ViroScene) { - var sceneKey = undefined; - var scene = undefined; + push = (param1?: ViroScene | string, param2?: ViroScene) => { + let sceneKey = undefined; + let scene = undefined; if (typeof param1 == "string") { sceneKey = param1; scene = param2; @@ -182,7 +219,7 @@ export class ViroARSceneNavigator extends React.Component { this.incrementSceneReference(scene as ViroScene, sceneKey, false); this.addToHistory(sceneKey); - } + }; /** * Replace the top scene in the stack with the given scene. The remainder of the back @@ -193,11 +230,12 @@ export class ViroARSceneNavigator extends React.Component { * replace ("sceneKey", scene); * replace (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - replace(param1?: ViroScene | string, param2?: ViroScene) { - var sceneKey = undefined; - var scene = undefined; + replace = (param1?: ViroScene | string, param2?: ViroScene) => { + let sceneKey = undefined; + let scene = undefined; if (typeof param1 == "string") { sceneKey = param1; scene = param2; @@ -234,7 +272,7 @@ export class ViroARSceneNavigator extends React.Component { this.popHistoryByN(1); this.incrementSceneReference(scene as ViroScene, sceneKey, false); this.addToHistory(sceneKey); - } + }; /** * Jumps to a given scene that had been previously pushed. If the scene was not pushed, we @@ -246,11 +284,12 @@ export class ViroARSceneNavigator extends React.Component { * jump ("sceneKey", scene); * jump (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - jump(param1?: ViroScene | string, param2?: ViroScene) { - var sceneKey = undefined; - var scene = undefined; + jump = (param1?: ViroScene | string, param2?: ViroScene) => { + let sceneKey = undefined; + let scene = undefined; if (typeof param1 == "string") { sceneKey = param1; scene = param2; @@ -283,13 +322,22 @@ export class ViroARSceneNavigator extends React.Component { this.incrementSceneReference(scene as ViroScene, sceneKey, true); this.reorderHistory(sceneKey); - } + }; - pop() { + /** + * Pop 1 screen from the stack. + */ + pop = () => { this.popN(1); - } + }; - popN(n: number) { + /** + * Pop n screens from the stack. + * + * @param n number of scenes to pop + * @returns void + */ + popN = (n: number) => { if (n === 0) { return; } @@ -303,22 +351,24 @@ export class ViroARSceneNavigator extends React.Component { this.decrementReferenceForLastNScenes(n); this.popHistoryByN(n); - } + }; /** * Increments the reference count for a scene within sceneDictionary that is * mapped to the given sceneKey. If no scenes are found / mapped, we create * one, initialize it with a reference count of 1, and store it within the * sceneDictionary for future reference. + * + * @todo TODO: Document parameters. */ - incrementSceneReference( + incrementSceneReference = ( scene: ViroScene, sceneKey: string, limitOne: boolean - ) { - var currentSceneDictionary = this.state.sceneDictionary; + ) => { + const currentSceneDictionary = this.state.sceneDictionary; if (!(sceneKey in currentSceneDictionary)) { - var newScene = { + const newScene = { sceneClass: scene, tag: sceneKey, referenceCount: 0, @@ -327,7 +377,7 @@ export class ViroARSceneNavigator extends React.Component { } // Error out if there are no scenes matching the given sceneKey - var currentScene = currentSceneDictionary[sceneKey]; + const currentScene = currentSceneDictionary[sceneKey]; if (currentScene == null || currentScene == undefined) { console.log("ERROR: No scene found for: " + sceneKey); return; @@ -344,21 +394,22 @@ export class ViroARSceneNavigator extends React.Component { this.setState({ sceneDictionary: currentSceneDictionary, }); - } + }; /** * Decrements the reference count for the last N scenes within * the sceneHistory by 1. If nothing else references that given scene * (counts equals 0), we then remove that scene from sceneDictionary. + * + * @param n number to decrement by. */ - decrementReferenceForLastNScenes(n: number) { - var sceneHistory = this.state.sceneHistory; - var sceneDictionary = this.state.sceneDictionary; + decrementReferenceForLastNScenes = (n: number) => { + const { sceneHistory, sceneDictionary } = this.state; // Now update and release any reference counts - for (var i = 1; i <= n; i++) { - var sceneTag = sceneHistory[sceneHistory.length - i]; - var scene = sceneDictionary[sceneTag]; + for (let i = 1; i <= n; i++) { + const sceneTag = sceneHistory[sceneHistory.length - i]; + const scene = sceneDictionary[sceneTag]; scene.referenceCount--; if (scene.referenceCount <= 0) { @@ -372,31 +423,35 @@ export class ViroARSceneNavigator extends React.Component { this.setState({ sceneDictionary: sceneDictionary, }); - } + }; /** * Adds the given sceneKey to the sceneHistory and updates the currentSceneIndex to point * to the scene on the top of the history stack (the most recent scene). + * + * @param sceneKey scene to insert into the stack. */ - addToHistory(sceneKey: string) { - var updatedHistory = this.state.sceneHistory.concat([sceneKey]); - var currentIndex = this.getSceneIndex(sceneKey); + addToHistory = (sceneKey: string) => { + const updatedHistory = this.state.sceneHistory.concat([sceneKey]); + const currentIndex = this.getSceneIndex(sceneKey); this.setState({ currentSceneIndex: currentIndex, sceneHistory: updatedHistory, }); - } + }; /** * Instead of preserving history, we find the last pushed sceneKey within the history stack * matching the given sceneKey and re-order it to the front. We then update the * currentSceneIndex to point to the scene on the top of the history stack * (the most recent scene). + * + * @param sceneKey scene to put at the top of the stack. */ - reorderHistory(sceneKey: string) { + reorderHistory = (sceneKey: string) => { // Find the last sceneKey within sceneHistory and remove it. - var sceneHistory = this.state.sceneHistory; - for (var i = sceneHistory.length - 1; i >= 0; i--) { + const { sceneHistory } = this.state; + for (let i = sceneHistory.length - 1; i >= 0; i--) { if (sceneKey == sceneHistory[i]) { sceneHistory.splice(i, 1); break; @@ -404,18 +459,23 @@ export class ViroARSceneNavigator extends React.Component { } // Add back the sceneKey to the front of the History stack. - var updatedHistory = sceneHistory.concat([sceneKey]); - var currentIndex = this.getSceneIndex(sceneKey); + const updatedHistory = sceneHistory.concat([sceneKey]); + const currentIndex = this.getSceneIndex(sceneKey); this.setState({ currentSceneIndex: currentIndex, sceneHistory: updatedHistory, }); - } + }; + /** + * Pops the history entries by n screens. + * + * @param n number of history entries to pop. + */ popHistoryByN(n: number) { - var sceneHistory = this.state.sceneHistory; + const { sceneHistory } = this.state; sceneHistory.splice(sceneHistory.length - n, n); - var currentIndex = this.getSceneIndex( + const currentIndex = this.getSceneIndex( sceneHistory[sceneHistory.length - 1] ); @@ -426,10 +486,16 @@ export class ViroARSceneNavigator extends React.Component { }); } - getSceneIndex(sceneTag: string) { - var sceneDictionary = this.state.sceneDictionary; - var i = 0; - for (var sceneKey in sceneDictionary) { + /** + * Gets the index of a scene by the scene tag. + * + * @param sceneTag tag of the scene + * @returns the index of the scene + */ + getSceneIndex = (sceneTag: string) => { + const { sceneDictionary } = this.state; + let i = 0; + for (const sceneKey in sceneDictionary) { if (sceneTag == sceneDictionary[sceneKey].tag) { return i; } @@ -437,107 +503,67 @@ export class ViroARSceneNavigator extends React.Component { } // Unable to find the given sceneTag, return -1 return -1; - } - - /* - Starts recording video of the Viro renderer and external audio - - fileName - name of the file (without extension) - saveToCameraRoll - whether or not the file should also be saved to the camera roll - onError - callback function that accepts an errorCode. - */ - _startVideoRecording( - fileName: string, - saveToCameraRoll: boolean, - // TODO: What are the errorCodes? make a type for this - onError: (errorCode: number) => void - ) { - ViroARSceneNavigatorModule.startVideoRecording( - findNodeHandle(this), - fileName, - saveToCameraRoll, - onError - ); - } - - /* - Stops recording video of the Viro renderer - - returns Object w/ success, url and errorCode keys. - */ - async _stopVideoRecording() { - return await ViroARSceneNavigatorModule.stopVideoRecording( - findNodeHandle(this) - ); - } - - /* - Takes a screenshot of the Viro renderer - - fileName - name of the file (without extension) - saveToCameraRoll - whether or not the file should also be saved to the camera roll + }; - returns Object w/ success, url and errorCode keys. + /** + * TODO: Document _unproject + * + * @param point + * @returns */ - async _takeScreenshot(fileName: string, saveToCameraRoll: boolean) { - return await ViroARSceneNavigatorModule.takeScreenshot( - findNodeHandle(this), - fileName, - saveToCameraRoll - ); - } - - async _project(point: Viro3DPoint) { - return await ViroARSceneNavigatorModule.project( - findNodeHandle(this), - point - ); - } - - async _unproject(point: Viro3DPoint) { + _unproject = async (point: Viro3DPoint) => { return await ViroARSceneNavigatorModule.unproject( findNodeHandle(this), point ); - } - - /* - [iOS Only] Resets the tracking of the AR session. + }; - resetTracking - determines if the tracking should be reset. - removeAnchors - determines if the existing anchors should be removed too. + /** + * [iOS Only] + * + * Resets the tracking of the AR session. + * + * @param resetTracking - determines if the tracking should be reset. + * @param removeAnchors - determines if the existing anchors should be removed too. */ - _resetARSession(resetTracking: any, removeAnchors: any) { + _resetARSession = (resetTracking: any, removeAnchors: any) => { ViroARSceneNavigatorModule.resetARSession( findNodeHandle(this), resetTracking, removeAnchors ); - } - - /* - [iOS/ARKit 1.5+ Only] Allows the developer to offset the current world orgin - by the given transformation matrix. ie. if this is called twice with the - position [0, 0, 1], then current world origin will be at [0, 0, 2] from its - initial position (it's additive, not meant to replace the existing origin) + }; - worldOrigin - a dictionary that can contain a `position` and `rotation` key with - an array containing 3 floats (note: rotation is in degrees). + /** + * [iOS/ARKit 1.5+ Only] + * + * Allows the developer to offset the current world orgin + * by the given transformation matrix. ie. if this is called twice with the + * position [0, 0, 1], then current world origin will be at [0, 0, 2] from its + * initial position (it's additive, not meant to replace the existing origin) + * + * @param worldOrigin - a dictionary that can contain a `position` and `rotation` key with an + * array containing 3 floats (note: rotation is in degrees). */ - _setWorldOrigin(worldOrigin: ViroWorldOrigin) { + _setWorldOrigin = (worldOrigin: ViroWorldOrigin) => { ViroARSceneNavigatorModule.setWorldOrigin( findNodeHandle(this), worldOrigin ); - } + }; - _renderSceneStackItems() { + /** + * Renders the Scene Views in the stack. + * + * @returns Array of rendered Scene views. + */ + _renderSceneStackItems = () => { let views = []; - var i = 0; - var sceneDictionary = this.state.sceneDictionary; - for (var scene in sceneDictionary) { - var Component = sceneDictionary[scene].sceneClass.scene; - var props = sceneDictionary[scene].sceneClass.passProps; + let i = 0; + const { sceneDictionary } = this.state; + for (const scene in sceneDictionary) { + const Component = sceneDictionary[scene].sceneClass.scene; + const props = sceneDictionary[scene].sceneClass.passProps; views.push( { i++; } return views; - } + }; + + arSceneNavigator = { + push: this.push, + pop: this.pop, + popN: this.popN, + jump: this.jump, + replace: this.replace, + startVideoRecording: this._startVideoRecording, + stopVideoRecording: this._stopVideoRecording, + takeScreenshot: this._takeScreenshot, + resetARSession: this._resetARSession, + setWorldOrigin: this._setWorldOrigin, + project: this._project, + unproject: this._unproject, + viroAppProps: {} as any, + }; + sceneNavigator = { + push: this.push, + pop: this.pop, + popN: this.popN, + jump: this.jump, + replace: this.replace, + startVideoRecording: this._startVideoRecording, + stopVideoRecording: this._stopVideoRecording, + takeScreenshot: this._takeScreenshot, + resetARSession: this._resetARSession, + setWorldOrigin: this._setWorldOrigin, + project: this._project, + unproject: this._unproject, + viroAppProps: {} as any, + }; render() { // Uncomment this line to check for misnamed props //checkMisnamedProps("ViroARSceneNavigator", this.props); - var items = this._renderSceneStackItems(); + const items = this._renderSceneStackItems(); // update the arSceneNavigator with the latest given props on every render this.arSceneNavigator.viroAppProps = this.props.viroAppProps; @@ -590,7 +647,7 @@ export class ViroARSceneNavigator extends React.Component { } } -var styles = StyleSheet.create({ +const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", @@ -598,7 +655,7 @@ var styles = StyleSheet.create({ }, }); -var VRTARSceneNavigator = requireNativeComponent( +const VRTARSceneNavigator = requireNativeComponent( "VRTARSceneNavigator", // @ts-ignore ViroARSceneNavigator, diff --git a/components/Viro3DSceneNavigator.tsx b/components/Viro3DSceneNavigator.tsx index 68d8eed..e0fdf00 100644 --- a/components/Viro3DSceneNavigator.tsx +++ b/components/Viro3DSceneNavigator.tsx @@ -83,19 +83,6 @@ type State = { export class Viro3DSceneNavigator extends React.Component { _component: ViroNativeRef = null; - sceneNavigator = { - push: this.push, - pop: this.pop, - popN: this.popN, - jump: this.jump, - replace: this.replace, - // exitViro: this.exitViro, TODO: this was unused - recenterTracking: this._recenterTracking, - project: this._project, - unproject: this._unproject, - viroAppProps: {} as any, - }; - /** * Called from native when either the user physically decides to exit vr (hits * the "X" buton). @@ -349,8 +336,7 @@ export class Viro3DSceneNavigator extends React.Component { * (counts equals 0), we then remove that scene from sceneDictionary. */ decrementReferenceForLastNScenes(n: number) { - var sceneHistory = this.state.sceneHistory; - var sceneDictionary = this.state.sceneDictionary; + const { sceneHistory, sceneDictionary } = this.state; // Now update and release any reference counts for (var i = 1; i <= n; i++) { @@ -473,6 +459,19 @@ export class Viro3DSceneNavigator extends React.Component { ); } + sceneNavigator = { + push: this.push, + pop: this.pop, + popN: this.popN, + jump: this.jump, + replace: this.replace, + // exitViro: this.exitViro, TODO: this was unused + recenterTracking: this._recenterTracking, + project: this._project, + unproject: this._unproject, + viroAppProps: {} as any, + }; + render() { // Uncomment this line to check for misnamed props //checkMisnamedProps("Viro3DSceneNavigator", this.props); diff --git a/components/ViroVRSceneNavigator.tsx b/components/ViroVRSceneNavigator.tsx index 63a9780..54640a0 100644 --- a/components/ViroVRSceneNavigator.tsx +++ b/components/ViroVRSceneNavigator.tsx @@ -84,18 +84,6 @@ type Props = ViewProps & { * ViroVRSceneNavigator is used to transition between multiple scenes. */ export class ViroVRSceneNavigator extends React.Component { - sceneNavigator = { - push: this.push, - pop: this.pop, - popN: this.popN, - jump: this.jump, - replace: this.replace, - // exitViro: this.exitViro, // not defined? - project: this._project, - unproject: this._unproject, - recenterTracking: this._recenterTracking, - viroAppProps: {} as any, - }; _component: ViroNativeRef = null; /** @@ -472,6 +460,19 @@ export class ViroVRSceneNavigator extends React.Component { return views; } + sceneNavigator = { + push: this.push, + pop: this.pop, + popN: this.popN, + jump: this.jump, + replace: this.replace, + // exitViro: this.exitViro, // not defined? + project: this._project, + unproject: this._unproject, + recenterTracking: this._recenterTracking, + viroAppProps: {} as any, + }; + render() { var items = this._renderSceneStackItems(); diff --git a/dist/components/AR/ViroARSceneNavigator.d.ts b/dist/components/AR/ViroARSceneNavigator.d.ts index 2afbaf4..3c50f28 100644 --- a/dist/components/AR/ViroARSceneNavigator.d.ts +++ b/dist/components/AR/ViroARSceneNavigator.d.ts @@ -53,38 +53,43 @@ type State = { */ export declare class ViroARSceneNavigator extends React.Component { _component: ViroNativeRef; - arSceneNavigator: { - push: (param1?: ViroScene | string, param2?: ViroScene) => void; - pop: () => void; - popN: (n: number) => void; - jump: (param1?: ViroScene | string, param2?: ViroScene) => void; - replace: (param1?: ViroScene | string, param2?: ViroScene) => void; - startVideoRecording: (fileName: string, saveToCameraRoll: boolean, onError: (errorCode: number) => void) => void; - stopVideoRecording: () => Promise; - takeScreenshot: (fileName: string, saveToCameraRoll: boolean) => Promise; - resetARSession: (resetTracking: any, removeAnchors: any) => void; - setWorldOrigin: (worldOrigin: ViroWorldOrigin) => void; - project: (point: Viro3DPoint) => Promise; - unproject: (point: Viro3DPoint) => Promise; - viroAppProps: any; - }; - sceneNavigator: { - push: (param1?: ViroScene | string, param2?: ViroScene) => void; - pop: () => void; - popN: (n: number) => void; - jump: (param1?: ViroScene | string, param2?: ViroScene) => void; - replace: (param1?: ViroScene | string, param2?: ViroScene) => void; - startVideoRecording: (fileName: string, saveToCameraRoll: boolean, onError: (errorCode: number) => void) => void; - stopVideoRecording: () => Promise; - takeScreenshot: (fileName: string, saveToCameraRoll: boolean) => Promise; - resetARSession: (resetTracking: any, removeAnchors: any) => void; - setWorldOrigin: (worldOrigin: ViroWorldOrigin) => void; - project: (point: Viro3DPoint) => Promise; - unproject: (point: Viro3DPoint) => Promise; - viroAppProps: any; - }; constructor(props: Props); - getRandomTag(): string; + /** + * Starts recording video of the Viro renderer and external audio + * + * @param fileName - name of the file (without extension) + * @param saveToCameraRoll - whether or not the file should also be saved to the camera roll + * @param onError - callback function that accepts an errorCode. + */ + _startVideoRecording: (fileName: string, saveToCameraRoll: boolean, onError: (errorCode: number) => void) => void; + /** + * Stops recording the video of the Viro Renderer. + * + * returns Object w/ success, url and errorCode keys. + * @returns Promise that resolves when the video has stopped recording. + */ + _stopVideoRecording: () => Promise; + /** + * Takes a screenshot of the Viro renderer + * + * @param fileName - name of the file (without extension) + * @param saveToCameraRoll - whether or not the file should also be saved to the camera roll + * returns Object w/ success, url and errorCode keys. + */ + _takeScreenshot: (fileName: string, saveToCameraRoll: boolean) => Promise; + /** + * @todo document _project + * + * @param point + * @returns + */ + _project(point: Viro3DPoint): Promise; + /** + * Gets a random tag string. + * + * @returns a random tag. + */ + getRandomTag: () => string; /** * Pushes a scene and reference it with the given key if provided. * If the scene has been previously pushed, we simply show the scene again. @@ -97,9 +102,10 @@ export declare class ViroARSceneNavigator extends React.Component * push ("sceneKey", scene); * push (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - push(param1?: ViroScene | string, param2?: ViroScene): void; + push: (param1?: ViroScene | string, param2?: ViroScene) => void; /** * Replace the top scene in the stack with the given scene. The remainder of the back * history is kept in the same order as before. @@ -109,9 +115,10 @@ export declare class ViroARSceneNavigator extends React.Component * replace ("sceneKey", scene); * replace (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - replace(param1?: ViroScene | string, param2?: ViroScene): void; + replace: (param1?: ViroScene | string, param2?: ViroScene) => void; /** * Jumps to a given scene that had been previously pushed. If the scene was not pushed, we * then push and jump to it. The back history is re-ordered such that jumped to scenes are @@ -122,46 +129,131 @@ export declare class ViroARSceneNavigator extends React.Component * jump ("sceneKey", scene); * jump (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - jump(param1?: ViroScene | string, param2?: ViroScene): void; - pop(): void; - popN(n: number): void; + jump: (param1?: ViroScene | string, param2?: ViroScene) => void; + /** + * Pop 1 screen from the stack. + */ + pop: () => void; + /** + * Pop n screens from the stack. + * + * @param n number of scenes to pop + * @returns void + */ + popN: (n: number) => void; /** * Increments the reference count for a scene within sceneDictionary that is * mapped to the given sceneKey. If no scenes are found / mapped, we create * one, initialize it with a reference count of 1, and store it within the * sceneDictionary for future reference. + * + * @todo TODO: Document parameters. */ - incrementSceneReference(scene: ViroScene, sceneKey: string, limitOne: boolean): void; + incrementSceneReference: (scene: ViroScene, sceneKey: string, limitOne: boolean) => void; /** * Decrements the reference count for the last N scenes within * the sceneHistory by 1. If nothing else references that given scene * (counts equals 0), we then remove that scene from sceneDictionary. + * + * @param n number to decrement by. */ - decrementReferenceForLastNScenes(n: number): void; + decrementReferenceForLastNScenes: (n: number) => void; /** * Adds the given sceneKey to the sceneHistory and updates the currentSceneIndex to point * to the scene on the top of the history stack (the most recent scene). + * + * @param sceneKey scene to insert into the stack. */ - addToHistory(sceneKey: string): void; + addToHistory: (sceneKey: string) => void; /** * Instead of preserving history, we find the last pushed sceneKey within the history stack * matching the given sceneKey and re-order it to the front. We then update the * currentSceneIndex to point to the scene on the top of the history stack * (the most recent scene). + * + * @param sceneKey scene to put at the top of the stack. + */ + reorderHistory: (sceneKey: string) => void; + /** + * Pops the history entries by n screens. + * + * @param n number of history entries to pop. */ - reorderHistory(sceneKey: string): void; popHistoryByN(n: number): void; - getSceneIndex(sceneTag: string): number; - _startVideoRecording(fileName: string, saveToCameraRoll: boolean, onError: (errorCode: number) => void): void; - _stopVideoRecording(): Promise; - _takeScreenshot(fileName: string, saveToCameraRoll: boolean): Promise; - _project(point: Viro3DPoint): Promise; - _unproject(point: Viro3DPoint): Promise; - _resetARSession(resetTracking: any, removeAnchors: any): void; - _setWorldOrigin(worldOrigin: ViroWorldOrigin): void; - _renderSceneStackItems(): JSX.Element[]; + /** + * Gets the index of a scene by the scene tag. + * + * @param sceneTag tag of the scene + * @returns the index of the scene + */ + getSceneIndex: (sceneTag: string) => number; + /** + * TODO: Document _unproject + * + * @param point + * @returns + */ + _unproject: (point: Viro3DPoint) => Promise; + /** + * [iOS Only] + * + * Resets the tracking of the AR session. + * + * @param resetTracking - determines if the tracking should be reset. + * @param removeAnchors - determines if the existing anchors should be removed too. + */ + _resetARSession: (resetTracking: any, removeAnchors: any) => void; + /** + * [iOS/ARKit 1.5+ Only] + * + * Allows the developer to offset the current world orgin + * by the given transformation matrix. ie. if this is called twice with the + * position [0, 0, 1], then current world origin will be at [0, 0, 2] from its + * initial position (it's additive, not meant to replace the existing origin) + * + * @param worldOrigin - a dictionary that can contain a `position` and `rotation` key with an + * array containing 3 floats (note: rotation is in degrees). + */ + _setWorldOrigin: (worldOrigin: ViroWorldOrigin) => void; + /** + * Renders the Scene Views in the stack. + * + * @returns Array of rendered Scene views. + */ + _renderSceneStackItems: () => JSX.Element[]; + arSceneNavigator: { + push: (param1?: ViroScene | string, param2?: ViroScene) => void; + pop: () => void; + popN: (n: number) => void; + jump: (param1?: ViroScene | string, param2?: ViroScene) => void; + replace: (param1?: ViroScene | string, param2?: ViroScene) => void; + startVideoRecording: (fileName: string, saveToCameraRoll: boolean, onError: (errorCode: number) => void) => void; + stopVideoRecording: () => Promise; + takeScreenshot: (fileName: string, saveToCameraRoll: boolean) => Promise; + resetARSession: (resetTracking: any, removeAnchors: any) => void; + setWorldOrigin: (worldOrigin: ViroWorldOrigin) => void; + project: (point: Viro3DPoint) => Promise; + unproject: (point: Viro3DPoint) => Promise; + viroAppProps: any; + }; + sceneNavigator: { + push: (param1?: ViroScene | string, param2?: ViroScene) => void; + pop: () => void; + popN: (n: number) => void; + jump: (param1?: ViroScene | string, param2?: ViroScene) => void; + replace: (param1?: ViroScene | string, param2?: ViroScene) => void; + startVideoRecording: (fileName: string, saveToCameraRoll: boolean, onError: (errorCode: number) => void) => void; + stopVideoRecording: () => Promise; + takeScreenshot: (fileName: string, saveToCameraRoll: boolean) => Promise; + resetARSession: (resetTracking: any, removeAnchors: any) => void; + setWorldOrigin: (worldOrigin: ViroWorldOrigin) => void; + project: (point: Viro3DPoint) => Promise; + unproject: (point: Viro3DPoint) => Promise; + viroAppProps: any; + }; render(): JSX.Element; } export {}; diff --git a/dist/components/AR/ViroARSceneNavigator.js b/dist/components/AR/ViroARSceneNavigator.js index 208b90e..9cacfe5 100644 --- a/dist/components/AR/ViroARSceneNavigator.js +++ b/dist/components/AR/ViroARSceneNavigator.js @@ -38,54 +38,24 @@ exports.ViroARSceneNavigator = void 0; const React = __importStar(require("react")); const react_native_1 = require("react-native"); const ViroARSceneNavigatorModule = react_native_1.NativeModules.VRTARSceneNavigatorModule; -var mathRandomOffset = 0; +let mathRandomOffset = 0; /** * ViroARSceneNavigator is used to transition between multiple AR Scenes. */ class ViroARSceneNavigator extends React.Component { _component = null; - arSceneNavigator = { - push: this.push, - pop: this.pop, - popN: this.popN, - jump: this.jump, - replace: this.replace, - startVideoRecording: this._startVideoRecording, - stopVideoRecording: this._stopVideoRecording, - takeScreenshot: this._takeScreenshot, - resetARSession: this._resetARSession, - setWorldOrigin: this._setWorldOrigin, - project: this._project, - unproject: this._unproject, - viroAppProps: {}, - }; - sceneNavigator = { - push: this.push, - pop: this.pop, - popN: this.popN, - jump: this.jump, - replace: this.replace, - startVideoRecording: this._startVideoRecording, - stopVideoRecording: this._stopVideoRecording, - takeScreenshot: this._takeScreenshot, - resetARSession: this._resetARSession, - setWorldOrigin: this._setWorldOrigin, - project: this._project, - unproject: this._unproject, - viroAppProps: {}, - }; constructor(props) { super(props); - var initialSceneTag = this.props.initialSceneKey; + let initialSceneTag = this.props.initialSceneKey; if (initialSceneTag == null) { initialSceneTag = this.getRandomTag(); } - var scene = { + const scene = { sceneClass: this.props.initialScene, tag: initialSceneTag, referenceCount: 1, }; - var sceneDict = {}; + const sceneDict = {}; sceneDict[scene.tag] = scene; this.state = { sceneDictionary: sceneDict, @@ -93,11 +63,56 @@ class ViroARSceneNavigator extends React.Component { currentSceneIndex: 0, }; } - getRandomTag() { - var randomTag = Math.random() + mathRandomOffset; + /** + * Starts recording video of the Viro renderer and external audio + * + * @param fileName - name of the file (without extension) + * @param saveToCameraRoll - whether or not the file should also be saved to the camera roll + * @param onError - callback function that accepts an errorCode. + */ + _startVideoRecording = (fileName, saveToCameraRoll, + // TODO: What are the errorCodes? make a type for this + onError) => { + ViroARSceneNavigatorModule.startVideoRecording((0, react_native_1.findNodeHandle)(this), fileName, saveToCameraRoll, onError); + }; + /** + * Stops recording the video of the Viro Renderer. + * + * returns Object w/ success, url and errorCode keys. + * @returns Promise that resolves when the video has stopped recording. + */ + _stopVideoRecording = async () => { + return await ViroARSceneNavigatorModule.stopVideoRecording((0, react_native_1.findNodeHandle)(this)); + }; + /** + * Takes a screenshot of the Viro renderer + * + * @param fileName - name of the file (without extension) + * @param saveToCameraRoll - whether or not the file should also be saved to the camera roll + * returns Object w/ success, url and errorCode keys. + */ + _takeScreenshot = async (fileName, saveToCameraRoll) => { + return await ViroARSceneNavigatorModule.takeScreenshot((0, react_native_1.findNodeHandle)(this), fileName, saveToCameraRoll); + }; + /** + * @todo document _project + * + * @param point + * @returns + */ + async _project(point) { + return await ViroARSceneNavigatorModule.project((0, react_native_1.findNodeHandle)(this), point); + } + /** + * Gets a random tag string. + * + * @returns a random tag. + */ + getRandomTag = () => { + const randomTag = Math.random() + mathRandomOffset; mathRandomOffset++; return randomTag.toString(); - } + }; /** * Pushes a scene and reference it with the given key if provided. * If the scene has been previously pushed, we simply show the scene again. @@ -110,11 +125,12 @@ class ViroARSceneNavigator extends React.Component { * push ("sceneKey", scene); * push (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - push(param1, param2) { - var sceneKey = undefined; - var scene = undefined; + push = (param1, param2) => { + let sceneKey = undefined; + let scene = undefined; if (typeof param1 == "string") { sceneKey = param1; scene = param2; @@ -138,7 +154,7 @@ class ViroARSceneNavigator extends React.Component { } this.incrementSceneReference(scene, sceneKey, false); this.addToHistory(sceneKey); - } + }; /** * Replace the top scene in the stack with the given scene. The remainder of the back * history is kept in the same order as before. @@ -148,11 +164,12 @@ class ViroARSceneNavigator extends React.Component { * replace ("sceneKey", scene); * replace (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - replace(param1, param2) { - var sceneKey = undefined; - var scene = undefined; + replace = (param1, param2) => { + let sceneKey = undefined; + let scene = undefined; if (typeof param1 == "string") { sceneKey = param1; scene = param2; @@ -180,7 +197,7 @@ class ViroARSceneNavigator extends React.Component { this.popHistoryByN(1); this.incrementSceneReference(scene, sceneKey, false); this.addToHistory(sceneKey); - } + }; /** * Jumps to a given scene that had been previously pushed. If the scene was not pushed, we * then push and jump to it. The back history is re-ordered such that jumped to scenes are @@ -191,11 +208,12 @@ class ViroARSceneNavigator extends React.Component { * jump ("sceneKey", scene); * jump (scene); * - * @todo: use Typescript function overloading rather than this inaccurate solution + * @todo use Typescript function overloading rather than this inaccurate solution + * @todo document parameters */ - jump(param1, param2) { - var sceneKey = undefined; - var scene = undefined; + jump = (param1, param2) => { + let sceneKey = undefined; + let scene = undefined; if (typeof param1 == "string") { sceneKey = param1; scene = param2; @@ -219,11 +237,20 @@ class ViroARSceneNavigator extends React.Component { } this.incrementSceneReference(scene, sceneKey, true); this.reorderHistory(sceneKey); - } - pop() { + }; + /** + * Pop 1 screen from the stack. + */ + pop = () => { this.popN(1); - } - popN(n) { + }; + /** + * Pop n screens from the stack. + * + * @param n number of scenes to pop + * @returns void + */ + popN = (n) => { if (n === 0) { return; } @@ -233,17 +260,19 @@ class ViroARSceneNavigator extends React.Component { } this.decrementReferenceForLastNScenes(n); this.popHistoryByN(n); - } + }; /** * Increments the reference count for a scene within sceneDictionary that is * mapped to the given sceneKey. If no scenes are found / mapped, we create * one, initialize it with a reference count of 1, and store it within the * sceneDictionary for future reference. + * + * @todo TODO: Document parameters. */ - incrementSceneReference(scene, sceneKey, limitOne) { - var currentSceneDictionary = this.state.sceneDictionary; + incrementSceneReference = (scene, sceneKey, limitOne) => { + const currentSceneDictionary = this.state.sceneDictionary; if (!(sceneKey in currentSceneDictionary)) { - var newScene = { + const newScene = { sceneClass: scene, tag: sceneKey, referenceCount: 0, @@ -251,7 +280,7 @@ class ViroARSceneNavigator extends React.Component { currentSceneDictionary[sceneKey] = newScene; } // Error out if there are no scenes matching the given sceneKey - var currentScene = currentSceneDictionary[sceneKey]; + const currentScene = currentSceneDictionary[sceneKey]; if (currentScene == null || currentScene == undefined) { console.log("ERROR: No scene found for: " + sceneKey); return; @@ -265,19 +294,20 @@ class ViroARSceneNavigator extends React.Component { this.setState({ sceneDictionary: currentSceneDictionary, }); - } + }; /** * Decrements the reference count for the last N scenes within * the sceneHistory by 1. If nothing else references that given scene * (counts equals 0), we then remove that scene from sceneDictionary. + * + * @param n number to decrement by. */ - decrementReferenceForLastNScenes(n) { - var sceneHistory = this.state.sceneHistory; - var sceneDictionary = this.state.sceneDictionary; + decrementReferenceForLastNScenes = (n) => { + const { sceneHistory, sceneDictionary } = this.state; // Now update and release any reference counts - for (var i = 1; i <= n; i++) { - var sceneTag = sceneHistory[sceneHistory.length - i]; - var scene = sceneDictionary[sceneTag]; + for (let i = 1; i <= n; i++) { + const sceneTag = sceneHistory[sceneHistory.length - i]; + const scene = sceneDictionary[sceneTag]; scene.referenceCount--; if (scene.referenceCount <= 0) { delete sceneDictionary[sceneTag]; @@ -290,56 +320,71 @@ class ViroARSceneNavigator extends React.Component { this.setState({ sceneDictionary: sceneDictionary, }); - } + }; /** * Adds the given sceneKey to the sceneHistory and updates the currentSceneIndex to point * to the scene on the top of the history stack (the most recent scene). + * + * @param sceneKey scene to insert into the stack. */ - addToHistory(sceneKey) { - var updatedHistory = this.state.sceneHistory.concat([sceneKey]); - var currentIndex = this.getSceneIndex(sceneKey); + addToHistory = (sceneKey) => { + const updatedHistory = this.state.sceneHistory.concat([sceneKey]); + const currentIndex = this.getSceneIndex(sceneKey); this.setState({ currentSceneIndex: currentIndex, sceneHistory: updatedHistory, }); - } + }; /** * Instead of preserving history, we find the last pushed sceneKey within the history stack * matching the given sceneKey and re-order it to the front. We then update the * currentSceneIndex to point to the scene on the top of the history stack * (the most recent scene). + * + * @param sceneKey scene to put at the top of the stack. */ - reorderHistory(sceneKey) { + reorderHistory = (sceneKey) => { // Find the last sceneKey within sceneHistory and remove it. - var sceneHistory = this.state.sceneHistory; - for (var i = sceneHistory.length - 1; i >= 0; i--) { + const { sceneHistory } = this.state; + for (let i = sceneHistory.length - 1; i >= 0; i--) { if (sceneKey == sceneHistory[i]) { sceneHistory.splice(i, 1); break; } } // Add back the sceneKey to the front of the History stack. - var updatedHistory = sceneHistory.concat([sceneKey]); - var currentIndex = this.getSceneIndex(sceneKey); + const updatedHistory = sceneHistory.concat([sceneKey]); + const currentIndex = this.getSceneIndex(sceneKey); this.setState({ currentSceneIndex: currentIndex, sceneHistory: updatedHistory, }); - } + }; + /** + * Pops the history entries by n screens. + * + * @param n number of history entries to pop. + */ popHistoryByN(n) { - var sceneHistory = this.state.sceneHistory; + const { sceneHistory } = this.state; sceneHistory.splice(sceneHistory.length - n, n); - var currentIndex = this.getSceneIndex(sceneHistory[sceneHistory.length - 1]); + const currentIndex = this.getSceneIndex(sceneHistory[sceneHistory.length - 1]); // Finally update all states this.setState({ currentSceneIndex: currentIndex, sceneHistory: sceneHistory, }); } - getSceneIndex(sceneTag) { - var sceneDictionary = this.state.sceneDictionary; - var i = 0; - for (var sceneKey in sceneDictionary) { + /** + * Gets the index of a scene by the scene tag. + * + * @param sceneTag tag of the scene + * @returns the index of the scene + */ + getSceneIndex = (sceneTag) => { + const { sceneDictionary } = this.state; + let i = 0; + for (const sceneKey in sceneDictionary) { if (sceneTag == sceneDictionary[sceneKey].tag) { return i; } @@ -347,81 +392,92 @@ class ViroARSceneNavigator extends React.Component { } // Unable to find the given sceneTag, return -1 return -1; - } - /* - Starts recording video of the Viro renderer and external audio - - fileName - name of the file (without extension) - saveToCameraRoll - whether or not the file should also be saved to the camera roll - onError - callback function that accepts an errorCode. - */ - _startVideoRecording(fileName, saveToCameraRoll, - // TODO: What are the errorCodes? make a type for this - onError) { - ViroARSceneNavigatorModule.startVideoRecording((0, react_native_1.findNodeHandle)(this), fileName, saveToCameraRoll, onError); - } - /* - Stops recording video of the Viro renderer - - returns Object w/ success, url and errorCode keys. - */ - async _stopVideoRecording() { - return await ViroARSceneNavigatorModule.stopVideoRecording((0, react_native_1.findNodeHandle)(this)); - } - /* - Takes a screenshot of the Viro renderer - - fileName - name of the file (without extension) - saveToCameraRoll - whether or not the file should also be saved to the camera roll - - returns Object w/ success, url and errorCode keys. + }; + /** + * TODO: Document _unproject + * + * @param point + * @returns */ - async _takeScreenshot(fileName, saveToCameraRoll) { - return await ViroARSceneNavigatorModule.takeScreenshot((0, react_native_1.findNodeHandle)(this), fileName, saveToCameraRoll); - } - async _project(point) { - return await ViroARSceneNavigatorModule.project((0, react_native_1.findNodeHandle)(this), point); - } - async _unproject(point) { + _unproject = async (point) => { return await ViroARSceneNavigatorModule.unproject((0, react_native_1.findNodeHandle)(this), point); - } - /* - [iOS Only] Resets the tracking of the AR session. - - resetTracking - determines if the tracking should be reset. - removeAnchors - determines if the existing anchors should be removed too. + }; + /** + * [iOS Only] + * + * Resets the tracking of the AR session. + * + * @param resetTracking - determines if the tracking should be reset. + * @param removeAnchors - determines if the existing anchors should be removed too. */ - _resetARSession(resetTracking, removeAnchors) { + _resetARSession = (resetTracking, removeAnchors) => { ViroARSceneNavigatorModule.resetARSession((0, react_native_1.findNodeHandle)(this), resetTracking, removeAnchors); - } - /* - [iOS/ARKit 1.5+ Only] Allows the developer to offset the current world orgin - by the given transformation matrix. ie. if this is called twice with the - position [0, 0, 1], then current world origin will be at [0, 0, 2] from its - initial position (it's additive, not meant to replace the existing origin) - - worldOrigin - a dictionary that can contain a `position` and `rotation` key with - an array containing 3 floats (note: rotation is in degrees). + }; + /** + * [iOS/ARKit 1.5+ Only] + * + * Allows the developer to offset the current world orgin + * by the given transformation matrix. ie. if this is called twice with the + * position [0, 0, 1], then current world origin will be at [0, 0, 2] from its + * initial position (it's additive, not meant to replace the existing origin) + * + * @param worldOrigin - a dictionary that can contain a `position` and `rotation` key with an + * array containing 3 floats (note: rotation is in degrees). */ - _setWorldOrigin(worldOrigin) { + _setWorldOrigin = (worldOrigin) => { ViroARSceneNavigatorModule.setWorldOrigin((0, react_native_1.findNodeHandle)(this), worldOrigin); - } - _renderSceneStackItems() { + }; + /** + * Renders the Scene Views in the stack. + * + * @returns Array of rendered Scene views. + */ + _renderSceneStackItems = () => { let views = []; - var i = 0; - var sceneDictionary = this.state.sceneDictionary; - for (var scene in sceneDictionary) { - var Component = sceneDictionary[scene].sceneClass.scene; - var props = sceneDictionary[scene].sceneClass.passProps; + let i = 0; + const { sceneDictionary } = this.state; + for (const scene in sceneDictionary) { + const Component = sceneDictionary[scene].sceneClass.scene; + const props = sceneDictionary[scene].sceneClass.passProps; views.push(); i++; } return views; - } + }; + arSceneNavigator = { + push: this.push, + pop: this.pop, + popN: this.popN, + jump: this.jump, + replace: this.replace, + startVideoRecording: this._startVideoRecording, + stopVideoRecording: this._stopVideoRecording, + takeScreenshot: this._takeScreenshot, + resetARSession: this._resetARSession, + setWorldOrigin: this._setWorldOrigin, + project: this._project, + unproject: this._unproject, + viroAppProps: {}, + }; + sceneNavigator = { + push: this.push, + pop: this.pop, + popN: this.popN, + jump: this.jump, + replace: this.replace, + startVideoRecording: this._startVideoRecording, + stopVideoRecording: this._stopVideoRecording, + takeScreenshot: this._takeScreenshot, + resetARSession: this._resetARSession, + setWorldOrigin: this._setWorldOrigin, + project: this._project, + unproject: this._unproject, + viroAppProps: {}, + }; render() { // Uncomment this line to check for misnamed props //checkMisnamedProps("ViroARSceneNavigator", this.props); - var items = this._renderSceneStackItems(); + const items = this._renderSceneStackItems(); // update the arSceneNavigator with the latest given props on every render this.arSceneNavigator.viroAppProps = this.props.viroAppProps; this.sceneNavigator.viroAppProps = this.props.viroAppProps; @@ -443,14 +499,14 @@ class ViroARSceneNavigator extends React.Component { } } exports.ViroARSceneNavigator = ViroARSceneNavigator; -var styles = react_native_1.StyleSheet.create({ +const styles = react_native_1.StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", }, }); -var VRTARSceneNavigator = (0, react_native_1.requireNativeComponent)("VRTARSceneNavigator", +const VRTARSceneNavigator = (0, react_native_1.requireNativeComponent)("VRTARSceneNavigator", // @ts-ignore ViroARSceneNavigator, { nativeOnly: { currentSceneIndex: true }, diff --git a/dist/components/Viro3DSceneNavigator.d.ts b/dist/components/Viro3DSceneNavigator.d.ts index bd3f6ef..6857925 100644 --- a/dist/components/Viro3DSceneNavigator.d.ts +++ b/dist/components/Viro3DSceneNavigator.d.ts @@ -61,17 +61,6 @@ type State = { */ export declare class Viro3DSceneNavigator extends React.Component { _component: ViroNativeRef; - sceneNavigator: { - push: (param1?: ViroScene | string, param2?: ViroScene) => void; - pop: () => void; - popN: (n: number) => void; - jump: (param1?: ViroScene | string, param2?: ViroScene) => void; - replace: (param1?: ViroScene | string, param2?: ViroScene) => void; - recenterTracking: () => void; - project: (point: Viro3DPoint) => Promise; - unproject: (point: Viro3DPoint) => Promise; - viroAppProps: any; - }; /** * Called from native when either the user physically decides to exit vr (hits * the "X" buton). @@ -152,6 +141,17 @@ export declare class Viro3DSceneNavigator extends React.Component _renderSceneStackItems(): JSX.Element[]; _project(point: Viro3DPoint): Promise; _unproject(point: Viro3DPoint): Promise; + sceneNavigator: { + push: (param1?: ViroScene | string, param2?: ViroScene) => void; + pop: () => void; + popN: (n: number) => void; + jump: (param1?: ViroScene | string, param2?: ViroScene) => void; + replace: (param1?: ViroScene | string, param2?: ViroScene) => void; + recenterTracking: () => void; + project: (point: Viro3DPoint) => Promise; + unproject: (point: Viro3DPoint) => Promise; + viroAppProps: any; + }; render(): JSX.Element; } export {}; diff --git a/dist/components/Viro3DSceneNavigator.js b/dist/components/Viro3DSceneNavigator.js index 5185cb5..5200277 100644 --- a/dist/components/Viro3DSceneNavigator.js +++ b/dist/components/Viro3DSceneNavigator.js @@ -44,18 +44,6 @@ var mathRandomOffset = 0; */ class Viro3DSceneNavigator extends React.Component { _component = null; - sceneNavigator = { - push: this.push, - pop: this.pop, - popN: this.popN, - jump: this.jump, - replace: this.replace, - // exitViro: this.exitViro, TODO: this was unused - recenterTracking: this._recenterTracking, - project: this._project, - unproject: this._unproject, - viroAppProps: {}, - }; /** * Called from native when either the user physically decides to exit vr (hits * the "X" buton). @@ -261,8 +249,7 @@ class Viro3DSceneNavigator extends React.Component { * (counts equals 0), we then remove that scene from sceneDictionary. */ decrementReferenceForLastNScenes(n) { - var sceneHistory = this.state.sceneHistory; - var sceneDictionary = this.state.sceneDictionary; + const { sceneHistory, sceneDictionary } = this.state; // Now update and release any reference counts for (var i = 1; i <= n; i++) { var sceneTag = sceneHistory[sceneHistory.length - i]; @@ -358,6 +345,18 @@ class Viro3DSceneNavigator extends React.Component { async _unproject(point) { return await Viro3DSceneNavigatorModule.unproject((0, react_native_1.findNodeHandle)(this), point); } + sceneNavigator = { + push: this.push, + pop: this.pop, + popN: this.popN, + jump: this.jump, + replace: this.replace, + // exitViro: this.exitViro, TODO: this was unused + recenterTracking: this._recenterTracking, + project: this._project, + unproject: this._unproject, + viroAppProps: {}, + }; render() { // Uncomment this line to check for misnamed props //checkMisnamedProps("Viro3DSceneNavigator", this.props); diff --git a/dist/components/ViroVRSceneNavigator.d.ts b/dist/components/ViroVRSceneNavigator.d.ts index d8a36bd..3b14d93 100644 --- a/dist/components/ViroVRSceneNavigator.d.ts +++ b/dist/components/ViroVRSceneNavigator.d.ts @@ -59,17 +59,6 @@ type Props = ViewProps & { * ViroVRSceneNavigator is used to transition between multiple scenes. */ export declare class ViroVRSceneNavigator extends React.Component { - sceneNavigator: { - push: (param1?: ViroScene | string, param2?: ViroScene) => void; - pop: () => void; - popN: (n: number) => void; - jump: (param1?: ViroScene | string, param2?: ViroScene) => void; - replace: (param1?: ViroScene | string, param2?: ViroScene) => void; - project: (point: Viro3DPoint) => Promise; - unproject: (point: Viro3DPoint) => Promise; - recenterTracking: () => void; - viroAppProps: any; - }; _component: ViroNativeRef; /** * Called from native when either the user physically decides to exit vr (hits @@ -151,6 +140,17 @@ export declare class ViroVRSceneNavigator extends React.Component _project(point: Viro3DPoint): Promise; _unproject(point: Viro3DPoint): Promise; _renderSceneStackItems(): JSX.Element[]; + sceneNavigator: { + push: (param1?: ViroScene | string, param2?: ViroScene) => void; + pop: () => void; + popN: (n: number) => void; + jump: (param1?: ViroScene | string, param2?: ViroScene) => void; + replace: (param1?: ViroScene | string, param2?: ViroScene) => void; + project: (point: Viro3DPoint) => Promise; + unproject: (point: Viro3DPoint) => Promise; + recenterTracking: () => void; + viroAppProps: any; + }; render(): JSX.Element; } export {}; diff --git a/dist/components/ViroVRSceneNavigator.js b/dist/components/ViroVRSceneNavigator.js index 69f0b28..5b8e7fb 100644 --- a/dist/components/ViroVRSceneNavigator.js +++ b/dist/components/ViroVRSceneNavigator.js @@ -43,18 +43,6 @@ var mathRandomOffset = 0; * ViroVRSceneNavigator is used to transition between multiple scenes. */ class ViroVRSceneNavigator extends React.Component { - sceneNavigator = { - push: this.push, - pop: this.pop, - popN: this.popN, - jump: this.jump, - replace: this.replace, - // exitViro: this.exitViro, // not defined? - project: this._project, - unproject: this._unproject, - recenterTracking: this._recenterTracking, - viroAppProps: {}, - }; _component = null; /** * Called from native when either the user physically decides to exit vr (hits @@ -358,6 +346,18 @@ class ViroVRSceneNavigator extends React.Component { } return views; } + sceneNavigator = { + push: this.push, + pop: this.pop, + popN: this.popN, + jump: this.jump, + replace: this.replace, + // exitViro: this.exitViro, // not defined? + project: this._project, + unproject: this._unproject, + recenterTracking: this._recenterTracking, + viroAppProps: {}, + }; render() { var items = this._renderSceneStackItems(); // Uncomment this line to check for misnamed props diff --git a/package.json b/package.json index 62ebcc2..32f04cb 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "main": "dist/index.js", "module": "dist/index.js", "types": "dist/index.d.ts", - "version": "2.23.1", + "version": "2.23.2", "license": "MIT", "publishConfig": { "registry": "https://registry.npmjs.org/" @@ -63,4 +63,4 @@ "ts-node": "^10.9.2", "typescript": "^4.6.3" } -} +} \ No newline at end of file