@reactvision/react-viro 2.53.1 → 2.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +85 -46
  2. package/android/react_viro/react_viro-release.aar +0 -0
  3. package/android/viro_renderer/viro_renderer-release.aar +0 -0
  4. package/components/AR/ViroARCamera.tsx +5 -0
  5. package/components/AR/ViroARImageMarker.tsx +5 -0
  6. package/components/AR/ViroARObjectMarker.tsx +5 -0
  7. package/components/AR/ViroARPlane.tsx +5 -0
  8. package/components/AR/ViroARPlaneSelector.tsx +5 -0
  9. package/components/AR/ViroARScene.tsx +5 -0
  10. package/components/AR/ViroARSceneNavigator.tsx +84 -0
  11. package/components/AR/ViroCommonProps.ts +11 -0
  12. package/components/Material/ViroMaterials.ts +51 -0
  13. package/components/Studio/StudioARScene.tsx +368 -0
  14. package/components/Studio/StudioSceneNavigator.tsx +191 -0
  15. package/components/Studio/VRTStudioModule.ts +40 -0
  16. package/components/Studio/domain/animationRegistry.ts +86 -0
  17. package/components/Studio/domain/collisionBindingsRuntime.ts +93 -0
  18. package/components/Studio/domain/collisionPairKey.ts +15 -0
  19. package/components/Studio/domain/dragConfiguration.ts +48 -0
  20. package/components/Studio/domain/materialConfig.ts +276 -0
  21. package/components/Studio/domain/physicsConfig.ts +204 -0
  22. package/components/Studio/domain/sceneNavigationHandler.ts +150 -0
  23. package/components/Studio/domain/studioMaterials.ts +33 -0
  24. package/components/Studio/domain/triggerImageRegistry.ts +64 -0
  25. package/components/Studio/domain/useStudioShaderTimeUniforms.ts +51 -0
  26. package/components/Studio/domain/useStudioShaderViewportUniforms.ts +52 -0
  27. package/components/Studio/domain/viroNodeFactory.tsx +323 -0
  28. package/components/Studio/index.ts +18 -0
  29. package/components/Studio/types.ts +164 -0
  30. package/components/Types/ViroEvents.ts +53 -0
  31. package/components/Utilities/VRModuleOpenXR.ts +50 -0
  32. package/components/Utilities/VRQuestNavigatorBridge.ts +168 -0
  33. package/components/Utilities/ViroPlatform.ts +52 -0
  34. package/components/Utilities/ViroUtils.tsx +48 -0
  35. package/components/Utilities/ViroVersion.ts +1 -1
  36. package/components/Utilities/useAnySourceHover.ts +55 -0
  37. package/components/Utilities/useAnySourcePressed.ts +70 -0
  38. package/components/Viro360Image.tsx +7 -0
  39. package/components/ViroQuestEntryPoint.tsx +79 -0
  40. package/components/ViroVRSceneNavigator.tsx +44 -19
  41. package/components/ViroXRSceneNavigator.tsx +217 -0
  42. package/components/VisionOS/ViroVisionOSModule.ts +93 -0
  43. package/dist/components/AR/ViroARCamera.d.ts +1 -1
  44. package/dist/components/AR/ViroARCamera.js +5 -0
  45. package/dist/components/AR/ViroARImageMarker.d.ts +1 -1
  46. package/dist/components/AR/ViroARImageMarker.js +5 -0
  47. package/dist/components/AR/ViroARObjectMarker.d.ts +1 -1
  48. package/dist/components/AR/ViroARObjectMarker.js +5 -0
  49. package/dist/components/AR/ViroARPlane.d.ts +1 -1
  50. package/dist/components/AR/ViroARPlane.js +5 -0
  51. package/dist/components/AR/ViroARPlaneSelector.d.ts +1 -1
  52. package/dist/components/AR/ViroARPlaneSelector.js +5 -0
  53. package/dist/components/AR/ViroARScene.d.ts +1 -1
  54. package/dist/components/AR/ViroARScene.js +5 -0
  55. package/dist/components/AR/ViroARSceneNavigator.d.ts +36 -0
  56. package/dist/components/AR/ViroARSceneNavigator.js +41 -0
  57. package/dist/components/AR/ViroCommonProps.d.ts +11 -0
  58. package/dist/components/Material/ViroMaterials.d.ts +12 -0
  59. package/dist/components/Material/ViroMaterials.js +25 -0
  60. package/dist/components/ReactVisionClient.d.ts +25 -0
  61. package/dist/components/ReactVisionClient.js +11 -0
  62. package/dist/components/Studio/StudioARScene.d.ts +15 -0
  63. package/dist/components/Studio/StudioARScene.js +299 -0
  64. package/dist/components/Studio/StudioSceneNavigator.d.ts +31 -0
  65. package/dist/components/Studio/StudioSceneNavigator.js +174 -0
  66. package/dist/components/Studio/VRTStudioModule.d.ts +15 -0
  67. package/dist/components/Studio/VRTStudioModule.js +31 -0
  68. package/dist/components/Studio/domain/animationRegistry.d.ts +11 -0
  69. package/dist/components/Studio/domain/animationRegistry.js +67 -0
  70. package/dist/components/Studio/domain/collisionBindingsRuntime.d.ts +21 -0
  71. package/dist/components/Studio/domain/collisionBindingsRuntime.js +54 -0
  72. package/dist/components/Studio/domain/collisionPairKey.d.ts +8 -0
  73. package/dist/components/Studio/domain/collisionPairKey.js +15 -0
  74. package/dist/components/Studio/domain/dragConfiguration.d.ts +20 -0
  75. package/dist/components/Studio/domain/dragConfiguration.js +37 -0
  76. package/dist/components/Studio/domain/materialConfig.d.ts +56 -0
  77. package/dist/components/Studio/domain/materialConfig.js +239 -0
  78. package/dist/components/Studio/domain/physicsConfig.d.ts +69 -0
  79. package/dist/components/Studio/domain/physicsConfig.js +165 -0
  80. package/dist/components/Studio/domain/sceneNavigationHandler.d.ts +12 -0
  81. package/dist/components/Studio/domain/sceneNavigationHandler.js +112 -0
  82. package/dist/components/Studio/domain/studioMaterials.d.ts +6 -0
  83. package/dist/components/Studio/domain/studioMaterials.js +30 -0
  84. package/dist/components/Studio/domain/triggerImageRegistry.d.ts +13 -0
  85. package/dist/components/Studio/domain/triggerImageRegistry.js +47 -0
  86. package/dist/components/Studio/domain/useStudioShaderTimeUniforms.d.ts +6 -0
  87. package/dist/components/Studio/domain/useStudioShaderTimeUniforms.js +48 -0
  88. package/dist/components/Studio/domain/useStudioShaderViewportUniforms.d.ts +6 -0
  89. package/dist/components/Studio/domain/useStudioShaderViewportUniforms.js +48 -0
  90. package/dist/components/Studio/domain/viroNodeFactory.d.ts +28 -0
  91. package/dist/components/Studio/domain/viroNodeFactory.js +193 -0
  92. package/dist/components/Studio/index.d.ts +3 -0
  93. package/dist/components/Studio/index.js +7 -0
  94. package/dist/components/Studio/types.d.ts +149 -0
  95. package/dist/components/Studio/types.js +4 -0
  96. package/dist/components/Types/ViroEvents.d.ts +49 -1
  97. package/dist/components/Types/ViroEvents.js +1 -0
  98. package/dist/components/Utilities/VRModuleOpenXR.d.ts +32 -0
  99. package/dist/components/Utilities/VRModuleOpenXR.js +44 -0
  100. package/dist/components/Utilities/VRQuestNavigatorBridge.d.ts +85 -0
  101. package/dist/components/Utilities/VRQuestNavigatorBridge.js +124 -0
  102. package/dist/components/Utilities/ViroPlatform.d.ts +10 -0
  103. package/dist/components/Utilities/ViroPlatform.js +43 -0
  104. package/dist/components/Utilities/ViroUtils.d.ts +19 -0
  105. package/dist/components/Utilities/ViroUtils.js +34 -0
  106. package/dist/components/Utilities/ViroVersion.d.ts +1 -1
  107. package/dist/components/Utilities/ViroVersion.js +1 -1
  108. package/dist/components/Utilities/useAnySourceHover.d.ts +36 -0
  109. package/dist/components/Utilities/useAnySourceHover.js +48 -0
  110. package/dist/components/Utilities/useAnySourcePressed.d.ts +37 -0
  111. package/dist/components/Utilities/useAnySourcePressed.js +61 -0
  112. package/dist/components/Viro360Image.d.ts +7 -0
  113. package/dist/components/ViroQuestEntryPoint.d.ts +13 -0
  114. package/dist/components/ViroQuestEntryPoint.js +104 -0
  115. package/dist/components/ViroVRSceneNavigator.d.ts +24 -10
  116. package/dist/components/ViroVRSceneNavigator.js +21 -18
  117. package/dist/components/ViroXRSceneNavigator.d.ts +54 -0
  118. package/dist/components/ViroXRSceneNavigator.js +173 -0
  119. package/dist/components/VisionOS/ViroVisionOSModule.d.ts +65 -0
  120. package/dist/components/VisionOS/ViroVisionOSModule.js +91 -0
  121. package/dist/index.d.ts +16 -3
  122. package/dist/index.js +34 -2
  123. package/dist/plugins/withViro.d.ts +28 -1
  124. package/dist/plugins/withViroAndroid.js +312 -7
  125. package/dist/plugins/withViroIos.js +17 -8
  126. package/dist/plugins/withViroVisionOS.d.ts +24 -0
  127. package/dist/plugins/withViroVisionOS.js +265 -0
  128. package/index.ts +66 -0
  129. package/ios/ViroReact.podspec +15 -5
  130. package/ios/dist/ViroRenderer/ViroKit.framework/ARCoreCoreMLSemanticsResources.bundle/Info.plist +0 -0
  131. package/ios/dist/ViroRenderer/ViroKit.framework/ARCoreResources.bundle/Info.plist +0 -0
  132. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROARSession.h +30 -1
  133. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROARSessioniOS.h +16 -0
  134. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROGLTFLoader.h +34 -0
  135. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROInputControllerBase.h +74 -0
  136. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROInputType.h +11 -3
  137. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROMaterial.h +29 -0
  138. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROMorpher.h +4 -0
  139. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROPlatformUtil.h +13 -0
  140. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROPortal.h +17 -0
  141. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VRORenderContext.h +41 -0
  142. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VRORenderer.h +23 -0
  143. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROSemantics.h +14 -0
  144. package/ios/dist/ViroRenderer/ViroKit.framework/Headers/VROViewAR.h +11 -0
  145. package/ios/dist/ViroRenderer/ViroKit.framework/Info.plist +0 -0
  146. package/ios/dist/ViroRenderer/ViroKit.framework/Shaders.dat +1 -1
  147. package/ios/dist/ViroRenderer/ViroKit.framework/ViroKit +0 -0
  148. package/ios/dist/ViroRenderer/ViroKit.podspec +5 -0
  149. package/ios/dist/include/VRT360Image.h +1 -0
  150. package/ios/dist/include/VRTARSceneNavigator.h +7 -0
  151. package/ios/dist/include/VRTStudioModule.h +6 -0
  152. package/ios/dist/lib/libViroReact.a +0 -0
  153. package/package.json +8 -8
@@ -37,6 +37,13 @@ type Props = ViewProps & {
37
37
  format?: "RGBA8" | "RGB565";
38
38
  steroMode?: "LeftRight" | "RightLeft" | "TopBottom" | "BottomTop" | "None";
39
39
  isHdr?: boolean;
40
+ /**
41
+ * When true, the image is rendered as a sky-effect overlay: it appears only over pixels
42
+ * semantically labeled as sky by ARCore/ARKit scene semantics, using alpha blending via
43
+ * the confidence texture for smooth boundary transitions. Requires scene semantics to be
44
+ * enabled on the AR session. Has no effect in VR mode. Default false.
45
+ */
46
+ skyEffect?: boolean;
40
47
  /**
41
48
  * Callback triggered when we are processing the assets to be
42
49
  * displayed in this 360 Photo (either downloading / reading from file).
@@ -0,0 +1,79 @@
1
+ import * as React from "react";
2
+ import { BackHandler, findNodeHandle, StyleSheet } from "react-native";
3
+ import {
4
+ VRQuestNavigatorBridge,
5
+ VRQuestIntent,
6
+ } from "./Utilities/VRQuestNavigatorBridge";
7
+ import { exitVRScene } from "./Utilities/VRModuleOpenXR";
8
+ import { ViroVRSceneNavigator } from "./ViroVRSceneNavigator";
9
+
10
+ /**
11
+ * Drop-in root component for VRActivity on Meta Quest.
12
+ *
13
+ * The library auto-registers this as 'VRQuestScene' when imported, so most
14
+ * apps need no manual setup. ViroXRSceneNavigator (panel side) calls
15
+ * setIntent() with the initial scene and renderer config before launching
16
+ * VRActivity. This component reads that intent, mounts ViroVRSceneNavigator
17
+ * with key={intentKey} (fresh stack per intent), and populates the bridge
18
+ * viewTag so VRModuleOpenXR ops (recenterTracking, setPassthroughEnabled)
19
+ * work without a direct ref to ViroVRSceneNavigator.
20
+ */
21
+ export function ViroQuestEntryPoint() {
22
+ const [intent, setIntent] = React.useState<VRQuestIntent | null>(
23
+ () => VRQuestNavigatorBridge.getIntent()
24
+ );
25
+ const navRef = React.useRef<ViroVRSceneNavigator>(null);
26
+
27
+ React.useEffect(() => VRQuestNavigatorBridge.onIntent(setIntent), []);
28
+
29
+ // Wire hardware back button to exit VR. Apps that need custom back behaviour
30
+ // can call AppRegistry.registerComponent('VRQuestScene', ...) to override.
31
+ React.useEffect(() => {
32
+ const sub = BackHandler.addEventListener("hardwareBackPress", () => {
33
+ exitVRScene();
34
+ return true;
35
+ });
36
+ return () => sub.remove();
37
+ }, []);
38
+
39
+ // Forward bridge ops (push/pop/etc.) to the live navigator.
40
+ React.useEffect(() => {
41
+ if (!intent) return;
42
+ return VRQuestNavigatorBridge.subscribeOps((op) => {
43
+ const nav = navRef.current;
44
+ if (!nav) return;
45
+ if (op.type === "push") nav.push(op.scene);
46
+ else if (op.type === "pop") nav.pop();
47
+ else if (op.type === "popN") nav.popN(op.n);
48
+ else if (op.type === "replace") nav.replace(op.scene);
49
+ else if (op.type === "jump") nav.jump(op.scene);
50
+ });
51
+ }, [intent?.intentKey]);
52
+
53
+ // Publish the native view tag so VRModuleOpenXR callers can target this view.
54
+ React.useEffect(() => {
55
+ if (!intent) return;
56
+ const t = setTimeout(() => {
57
+ const tag = findNodeHandle(navRef.current);
58
+ if (tag != null) VRQuestNavigatorBridge.setViewTag(tag);
59
+ }, 100);
60
+ return () => {
61
+ clearTimeout(t);
62
+ VRQuestNavigatorBridge.setViewTag(null);
63
+ };
64
+ }, [intent?.intentKey]);
65
+
66
+ if (!intent) return null;
67
+
68
+ const { initialScene, rendererConfig } = intent;
69
+
70
+ return (
71
+ <ViroVRSceneNavigator
72
+ ref={navRef}
73
+ key={intent.intentKey}
74
+ initialScene={initialScene}
75
+ {...rendererConfig}
76
+ style={StyleSheet.absoluteFill}
77
+ />
78
+ );
79
+ }
@@ -19,7 +19,10 @@ import {
19
19
  StyleSheet,
20
20
  ViewProps,
21
21
  } from "react-native";
22
- import { ViroExitViroEvent } from "./Types/ViroEvents";
22
+ import {
23
+ ViroExitViroEvent,
24
+ ViroHandUpdateEvent,
25
+ } from "./Types/ViroEvents";
23
26
  import {
24
27
  Viro3DPoint,
25
28
  ViroNativeRef,
@@ -27,6 +30,10 @@ import {
27
30
  ViroSceneDictionary,
28
31
  } from "./Types/ViroUtils";
29
32
  const ViroSceneNavigatorModule = NativeModules.VRTSceneNavigatorModule;
33
+ const VRModuleOpenXR = NativeModules.VRModuleOpenXR as {
34
+ recenterTracking: (viewTag: number) => void;
35
+ setPassthroughEnabled: (viewTag: number, enabled: boolean) => void;
36
+ } | undefined;
30
37
 
31
38
  type State = {
32
39
  sceneDictionary: ViroSceneDictionary;
@@ -78,10 +85,27 @@ type Props = ViewProps & {
78
85
  bloomEnabled?: boolean;
79
86
  shadowsEnabled?: boolean;
80
87
  multisamplingEnabled?: boolean;
88
+
89
+ /** Enable XR_FB_passthrough mixed-reality camera feed (Quest 3 / Quest Pro). */
90
+ passthroughEnabled?: boolean;
91
+
92
+ /**
93
+ * Enable skeletal hand tracking (Quest — requires com.oculus.permission.HAND_TRACKING in manifest).
94
+ * Pinch and grab gestures fire the same onClick/onDrag events as controller buttons.
95
+ */
96
+ handTrackingEnabled?: boolean;
97
+
98
+ /**
99
+ * Per-frame skeletal hand joint data. Fires at display refresh rate (72/90 Hz).
100
+ * null for a hand means it is not currently tracked.
101
+ */
102
+ onHandUpdate?: (event: NativeSyntheticEvent<ViroHandUpdateEvent>) => void;
81
103
  };
82
104
 
83
105
  /**
84
106
  * ViroVRSceneNavigator is used to transition between multiple scenes.
107
+ * Intended for OVR / Google Cardboard VR mode on non-Quest Android devices.
108
+ * On Meta Quest use ViroXRSceneNavigator instead.
85
109
  */
86
110
  export class ViroVRSceneNavigator extends React.Component<Props, State> {
87
111
  _component: ViroNativeRef = null;
@@ -90,9 +114,9 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
90
114
  * Called from native when either the user physically decides to exit vr (hits
91
115
  * the "X" buton).
92
116
  */
93
- _onExitViro(_event: NativeSyntheticEvent<ViroExitViroEvent>) {
117
+ _onExitViro = (_event: NativeSyntheticEvent<ViroExitViroEvent>) => {
94
118
  this.props.onExitViro && this.props.onExitViro();
95
- }
119
+ };
96
120
 
97
121
  constructor(props: Props) {
98
122
  super(props);
@@ -134,7 +158,7 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
134
158
  *
135
159
  * @todo: use Typescript function overloading rather than this inaccurate solution
136
160
  */
137
- push(param1?: ViroScene | string, param2?: ViroScene) {
161
+ push = (param1?: ViroScene | string, param2?: ViroScene) => {
138
162
  var sceneKey = undefined;
139
163
  var scene = undefined;
140
164
  if (typeof param1 == "string") {
@@ -169,7 +193,7 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
169
193
 
170
194
  this.incrementSceneReference(scene as ViroScene, sceneKey, false);
171
195
  this.addToHistory(sceneKey);
172
- }
196
+ };
173
197
 
174
198
  /**
175
199
  * Replace the top scene in the stack with the given scene. The remainder of the back
@@ -182,7 +206,7 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
182
206
  *
183
207
  * @todo: use Typescript function overloading rather than this inaccurate solution
184
208
  */
185
- replace(param1?: ViroScene | string, param2?: ViroScene) {
209
+ replace = (param1?: ViroScene | string, param2?: ViroScene) => {
186
210
  var sceneKey = undefined;
187
211
  var scene = undefined;
188
212
  if (typeof param1 == "string") {
@@ -221,7 +245,7 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
221
245
  this.popHistoryByN(1);
222
246
  this.incrementSceneReference(scene as ViroScene, sceneKey, false);
223
247
  this.addToHistory(sceneKey);
224
- }
248
+ };
225
249
 
226
250
  /**
227
251
  * Jumps to a given scene that had been previously pushed. If the scene was not pushed, we
@@ -235,7 +259,7 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
235
259
  *
236
260
  * @todo: use Typescript function overloading rather than this inaccurate solution
237
261
  */
238
- jump(param1?: ViroScene | string, param2?: ViroScene) {
262
+ jump = (param1?: ViroScene | string, param2?: ViroScene) => {
239
263
  var sceneKey = undefined;
240
264
  var scene = undefined;
241
265
  if (typeof param1 == "string") {
@@ -270,13 +294,13 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
270
294
 
271
295
  this.incrementSceneReference(scene as ViroScene, sceneKey, true);
272
296
  this.reorderHistory(sceneKey);
273
- }
297
+ };
274
298
 
275
- pop() {
299
+ pop = () => {
276
300
  this.popN(1);
277
- }
301
+ };
278
302
 
279
- popN(n: number) {
303
+ popN = (n: number) => {
280
304
  if (n === 0) {
281
305
  return;
282
306
  }
@@ -290,7 +314,7 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
290
314
 
291
315
  this.decrementReferenceForLastNScenes(n);
292
316
  this.popHistoryByN(n);
293
- }
317
+ };
294
318
 
295
319
  /**
296
320
  * Increments the reference count for a scene within sceneDictionary that is
@@ -426,20 +450,20 @@ export class ViroVRSceneNavigator extends React.Component<Props, State> {
426
450
  return -1;
427
451
  }
428
452
 
429
- _recenterTracking() {
453
+ _recenterTracking = () => {
430
454
  ViroSceneNavigatorModule.recenterTracking(findNodeHandle(this));
431
- }
455
+ };
432
456
 
433
- async _project(point: Viro3DPoint) {
457
+ _project = async (point: Viro3DPoint) => {
434
458
  return await ViroSceneNavigatorModule.project(findNodeHandle(this), point);
435
- }
459
+ };
436
460
 
437
- async _unproject(point: Viro3DPoint) {
461
+ _unproject = async (point: Viro3DPoint) => {
438
462
  return await ViroSceneNavigatorModule.unproject(
439
463
  findNodeHandle(this),
440
464
  point
441
465
  );
442
- }
466
+ };
443
467
 
444
468
  _renderSceneStackItems() {
445
469
  let views = [];
@@ -516,6 +540,7 @@ var styles = StyleSheet.create({
516
540
  },
517
541
  });
518
542
 
543
+
519
544
  var VRTVRSceneNavigator = requireNativeComponent<any>(
520
545
  "VRTVRSceneNavigator",
521
546
  // @ts-ignore
@@ -0,0 +1,217 @@
1
+ import * as React from "react";
2
+ import { AppState, NativeModules, ViewProps } from "react-native";
3
+ import { ViroARSceneNavigator } from "./AR/ViroARSceneNavigator";
4
+ import { isQuest } from "./Utilities/ViroPlatform";
5
+ import { VRQuestNavigatorBridge } from "./Utilities/VRQuestNavigatorBridge";
6
+
7
+ const VRLauncher = NativeModules.VRLauncher as
8
+ | { launchVRScene?: () => void }
9
+ | undefined;
10
+
11
+ // Quest VR requires a lifecycle-correct VRActivity that drives
12
+ // ReactHostImpl.onHostResume(VRActivity) on entry. The skipActivityIdentity
13
+ // AssertionOnHostPause feature flag (used to suppress the racy MainActivity.
14
+ // onPause assertion when currentActivity has been promoted to VR) is only
15
+ // honored on RN >= 0.83. Without it, MainActivity.onPause hard-crashes via
16
+ // Assertions.assertCondition, so the entire VR path requires RN 0.83+.
17
+ // AR continues to work on RN >= 0.81 (Expo 54+) — only the Quest VR launch
18
+ // is gated.
19
+ const MIN_RN_FOR_VR = { major: 0, minor: 83 };
20
+
21
+ function checkRNVersionForVR(): void {
22
+ let version = "unknown";
23
+ try {
24
+ version = require("react-native/package.json").version as string;
25
+ const [maj, min] = version.split(".").map((n) => parseInt(n, 10));
26
+ if (
27
+ Number.isFinite(maj) &&
28
+ Number.isFinite(min) &&
29
+ (maj > MIN_RN_FOR_VR.major ||
30
+ (maj === MIN_RN_FOR_VR.major && min >= MIN_RN_FOR_VR.minor))
31
+ ) {
32
+ return;
33
+ }
34
+ } catch {
35
+ // fall through to throw with version="unknown"
36
+ }
37
+ throw new Error(
38
+ `[Viro] Meta Quest VR requires React Native >= ${MIN_RN_FOR_VR.major}.${MIN_RN_FOR_VR.minor} ` +
39
+ `(Expo SDK >= 55). Detected: ${version}. ` +
40
+ `AR features still work on this version — only ViroXRSceneNavigator's VR path on Quest is gated.`
41
+ );
42
+ }
43
+
44
+ type SceneFactory = { scene: () => React.JSX.Element };
45
+
46
+ type Props = ViewProps & {
47
+ /**
48
+ * Scene used on both AR and VR platforms when no platform-specific scene is provided.
49
+ * Most apps want a different scene per platform — pass `arInitialScene` and
50
+ * `vrInitialScene` instead in that case.
51
+ */
52
+ initialScene?: SceneFactory;
53
+
54
+ /** Scene mounted on iOS / non-Quest Android (rendered via ViroARSceneNavigator). */
55
+ arInitialScene?: SceneFactory;
56
+
57
+ /**
58
+ * Scene mounted on Meta Quest (rendered via ViroVRSceneNavigator in VRActivity).
59
+ * On Quest, this scene is forwarded to VRActivity via VRQuestNavigatorBridge
60
+ * rather than rendered inline, because OpenXR exclusive display requires the
61
+ * VR intent category on the host Activity.
62
+ */
63
+ vrInitialScene?: SceneFactory;
64
+
65
+ // ── Forwarded to ViroARSceneNavigator ──────────────────────────────────────
66
+ worldAlignment?: "Gravity" | "GravityAndHeading" | "Camera";
67
+ autofocus?: boolean;
68
+ videoQuality?: "High" | "Low";
69
+ numberOfTrackedImages?: number;
70
+
71
+ // ── Forwarded to ViroVRSceneNavigator (Quest path via bridge) ──────────────
72
+ vrModeEnabled?: boolean;
73
+ passthroughEnabled?: boolean;
74
+ handTrackingEnabled?: boolean;
75
+ onExitViro?: () => void;
76
+
77
+ // ── Common ─────────────────────────────────────────────────────────────────
78
+ viroAppProps?: any;
79
+ hdrEnabled?: boolean;
80
+ pbrEnabled?: boolean;
81
+ bloomEnabled?: boolean;
82
+ shadowsEnabled?: boolean;
83
+ multisamplingEnabled?: boolean;
84
+ debug?: boolean;
85
+ };
86
+
87
+ /**
88
+ * Cross-reality scene navigator. Picks the right underlying navigator at runtime:
89
+ *
90
+ * - **iOS / non-Quest Android** → `ViroARSceneNavigator` (rendered inline)
91
+ * - **Meta Quest** → launches VRActivity via `VRLauncher.launchVRScene()` and
92
+ * forwards all navigator operations (push/pop/etc.) to the
93
+ * `ViroVRSceneNavigator` running there via `VRQuestNavigatorBridge`.
94
+ * Render output is null — VRActivity owns the display.
95
+ *
96
+ * Pass `arInitialScene` / `vrInitialScene` when the AR and VR scenes differ.
97
+ * When only `initialScene` is provided it is used for both modes.
98
+ *
99
+ * Renderer flags (`hdrEnabled`, `pbrEnabled`, `bloomEnabled`, `shadowsEnabled`,
100
+ * `passthroughEnabled`, etc.) are forwarded to ViroVRSceneNavigator on Quest
101
+ * via the intent bridge.
102
+ */
103
+ export const ViroXRSceneNavigator = React.forwardRef<unknown, Props>(
104
+ function ViroXRSceneNavigator(props, ref) {
105
+ const {
106
+ initialScene,
107
+ arInitialScene,
108
+ vrInitialScene,
109
+ // VR-only renderer config — forwarded via bridge on Quest
110
+ hdrEnabled,
111
+ pbrEnabled,
112
+ bloomEnabled,
113
+ shadowsEnabled,
114
+ multisamplingEnabled,
115
+ vrModeEnabled,
116
+ passthroughEnabled,
117
+ handTrackingEnabled,
118
+ onExitViro,
119
+ debug,
120
+ ...rest
121
+ } = props;
122
+
123
+ // Inner ref used on the AR path to capture the ViroARSceneNavigator instance.
124
+ const arRef = React.useRef<ViroARSceneNavigator>(null);
125
+
126
+ // Expose navigator interface on the ref.
127
+ // Quest: proxy push/pop/etc. through VRQuestNavigatorBridge to VRActivity.
128
+ // AR: expose the underlying ViroARSceneNavigator instance directly.
129
+ React.useImperativeHandle(ref, () => {
130
+ if (isQuest) {
131
+ const bridgeNav = {
132
+ push: (scene: any) => VRQuestNavigatorBridge.dispatchOp({ type: "push", scene }),
133
+ replace: (scene: any) => VRQuestNavigatorBridge.dispatchOp({ type: "replace", scene }),
134
+ jump: (scene: any) => VRQuestNavigatorBridge.dispatchOp({ type: "jump", scene }),
135
+ pop: () => VRQuestNavigatorBridge.dispatchOp({ type: "pop" }),
136
+ popN: (n: number) => VRQuestNavigatorBridge.dispatchOp({ type: "popN", n }),
137
+ };
138
+ return { sceneNavigator: bridgeNav, arSceneNavigator: bridgeNav };
139
+ }
140
+ return arRef.current as any;
141
+ }, []);
142
+
143
+ // Track AppState so we can detect background → active transitions.
144
+ const appStateRef = React.useRef(AppState.currentState);
145
+ // Timestamp at which AppState last left "active". Lets us distinguish a
146
+ // genuine Quest-menu return (background lasts seconds) from racy
147
+ // background→active bounces caused by the dual-Activity ReactHost
148
+ // transitioning state (background lasts <500ms). Only the former should
149
+ // re-launch VR; the latter would trigger a no-op startActivity that can
150
+ // contribute to the lifecycle storm in some configurations.
151
+ const leftActiveAtRef = React.useRef(0);
152
+
153
+ // On Quest: register the intent (scene + renderer config) then launch VRActivity.
154
+ // Also re-launch when the app returns from background (e.g. Quest system menu),
155
+ // because VRActivity auto-finishes when MainActivity resumes.
156
+ React.useEffect(() => {
157
+ if (!isQuest) return;
158
+ checkRNVersionForVR();
159
+ const scene = vrInitialScene ?? initialScene;
160
+ if (scene) {
161
+ VRQuestNavigatorBridge.setIntent(scene, {
162
+ hdrEnabled,
163
+ pbrEnabled,
164
+ bloomEnabled,
165
+ shadowsEnabled,
166
+ multisamplingEnabled,
167
+ vrModeEnabled,
168
+ passthroughEnabled,
169
+ handTrackingEnabled,
170
+ onExitViro,
171
+ debug,
172
+ });
173
+ }
174
+ VRQuestNavigatorBridge.setVRActive(true);
175
+ VRLauncher?.launchVRScene?.();
176
+
177
+ const sub = AppState.addEventListener("change", (nextState) => {
178
+ const prev = appStateRef.current;
179
+ appStateRef.current = nextState;
180
+ if (prev === "active" && nextState !== "active") {
181
+ leftActiveAtRef.current = Date.now();
182
+ }
183
+ // Re-launch VR when the app returns from being backgrounded by the system
184
+ // (Quest menu, home, recents). Explicit exitVRScene() clears isVRActive()
185
+ // before finishing VRActivity, so Activity-transition-driven background→active
186
+ // cycles are ignored here.
187
+ if (prev !== "active" && nextState === "active" && VRQuestNavigatorBridge.isVRActive()) {
188
+ // Skip if we were only briefly out of "active" — that's a racy
189
+ // dual-Activity ReactHost bounce, not a genuine menu return.
190
+ const backgroundedFor = Date.now() - leftActiveAtRef.current;
191
+ if (leftActiveAtRef.current > 0 && backgroundedFor < 1500) return;
192
+ VRQuestNavigatorBridge.setVRActive(true);
193
+ VRLauncher?.launchVRScene?.();
194
+ }
195
+ });
196
+ return () => sub.remove();
197
+ }, []);
198
+
199
+ // Quest renders nothing here — VRActivity owns the display.
200
+ if (isQuest) return null;
201
+
202
+ const scene = arInitialScene ?? initialScene;
203
+ if (!scene) {
204
+ console.warn(
205
+ "[Viro] ViroXRSceneNavigator requires `arInitialScene` or `initialScene`."
206
+ );
207
+ return null;
208
+ }
209
+ return (
210
+ <ViroARSceneNavigator
211
+ ref={arRef}
212
+ initialScene={scene}
213
+ {...rest}
214
+ />
215
+ );
216
+ }
217
+ );
@@ -0,0 +1,93 @@
1
+ /**
2
+ * ViroVisionOSModule
3
+ *
4
+ * JavaScript API for controlling the visionOS ImmersiveSpace.
5
+ * On iOS / Android the calls are no-ops (module returns false / resolves silently).
6
+ *
7
+ * ── Host-app setup required ──────────────────────────────────────────────────
8
+ *
9
+ * 1. Add the ImmersiveSpace to your SwiftUI App struct (visionOS only):
10
+ *
11
+ * #if os(visionOS)
12
+ * import ViroReact
13
+ * #endif
14
+ *
15
+ * @main struct MyApp: App {
16
+ * var body: some Scene {
17
+ * WindowGroup {
18
+ * ContentView()
19
+ * #if os(visionOS)
20
+ * .viroImmersiveSpaceController()
21
+ * #endif
22
+ * }
23
+ * #if os(visionOS)
24
+ * ImmersiveSpace(id: "ViroImmersive") {
25
+ * ViroImmersiveSpaceView()
26
+ * }
27
+ * .immersionStyle(selection: .constant(.mixed), in: .mixed, .full, .progressive)
28
+ * #endif
29
+ * }
30
+ * }
31
+ *
32
+ * 2. Call from JavaScript:
33
+ *
34
+ * import { ViroVisionOSModule } from '@reactvision/react-viro';
35
+ *
36
+ * await ViroVisionOSModule.enterImmersiveSpace('mixed');
37
+ * // ... render Viro scene inside ImmersiveSpace ...
38
+ * await ViroVisionOSModule.exitImmersiveSpace();
39
+ * ─────────────────────────────────────────────────────────────────────────────
40
+ */
41
+
42
+ import { NativeModules, Platform } from "react-native";
43
+
44
+ export type ImmersiveSpaceStyle = "mixed" | "full" | "progressive";
45
+
46
+ /** @internal — raw NativeModule reference */
47
+ const { VRTVisionOSModule } = NativeModules;
48
+
49
+ /**
50
+ * Returns true if the app is running on Apple Vision Pro (visionOS).
51
+ * Uses the native module constant; falls back to Platform.isVision when
52
+ * available (React Native 0.83+).
53
+ */
54
+ export function isVisionOS(): boolean {
55
+ // React Native 0.83+ exposes Platform.isVision on visionOS builds.
56
+ if ((Platform as any).isVision === true) return true;
57
+ // Fallback: check the native module constant.
58
+ return VRTVisionOSModule?.isVisionOS === true;
59
+ }
60
+
61
+ /**
62
+ * Opens the Viro ImmersiveSpace on visionOS.
63
+ *
64
+ * @param style "mixed" (default) — virtual content blended over passthrough
65
+ * "full" — fully virtual, passthrough hidden
66
+ * "progressive" — graduated immersion with crown dial
67
+ */
68
+ export async function enterImmersiveSpace(
69
+ style: ImmersiveSpaceStyle = "mixed"
70
+ ): Promise<boolean> {
71
+ if (!VRTVisionOSModule) {
72
+ if (__DEV__) {
73
+ console.warn("[Viro] VRTVisionOSModule not available on this platform");
74
+ }
75
+ return false;
76
+ }
77
+ return VRTVisionOSModule.enterImmersiveSpace(style);
78
+ }
79
+
80
+ /**
81
+ * Dismisses the Viro ImmersiveSpace and returns to the window layer.
82
+ */
83
+ export async function exitImmersiveSpace(): Promise<boolean> {
84
+ if (!VRTVisionOSModule) return false;
85
+ return VRTVisionOSModule.exitImmersiveSpace();
86
+ }
87
+
88
+ /** Convenience object matching the typical NativeModules pattern. */
89
+ export const ViroVisionOSModule = {
90
+ isVisionOS,
91
+ enterImmersiveSpace,
92
+ exitImmersiveSpace,
93
+ } as const;
@@ -3,5 +3,5 @@ import { ViewProps } from "react-native";
3
3
  import { ViroCamera } from "../ViroCamera";
4
4
  export declare class ViroARCamera extends React.Component<ViewProps> {
5
5
  _component: ViroCamera | null;
6
- render(): React.JSX.Element;
6
+ render(): React.JSX.Element | null;
7
7
  }
@@ -47,9 +47,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
47
47
  exports.ViroARCamera = void 0;
48
48
  const React = __importStar(require("react"));
49
49
  const ViroCamera_1 = require("../ViroCamera");
50
+ const ViroPlatform_1 = require("../Utilities/ViroPlatform");
50
51
  class ViroARCamera extends React.Component {
51
52
  _component = null;
52
53
  render() {
54
+ if (ViroPlatform_1.isQuest) {
55
+ console.warn("[Viro] ViroARCamera is not supported on Quest and will not render.");
56
+ return null;
57
+ }
53
58
  // Uncomment this to check props
54
59
  return (<ViroCamera_1.ViroCamera ref={(component) => {
55
60
  this._component = component;
@@ -19,5 +19,5 @@ export declare class ViroARImageMarker extends ViroBase<{}> {
19
19
  _onAnchorFound: (event: NativeSyntheticEvent<ViroARAnchorFoundEvent>) => void;
20
20
  _onAnchorUpdated: (event: NativeSyntheticEvent<ViroARAnchorUpdatedEvent>) => void;
21
21
  _onAnchorRemoved: (_event: NativeSyntheticEvent<ViroARAnchorRemovedEvent>) => void;
22
- render(): React.JSX.Element;
22
+ render(): React.JSX.Element | null;
23
23
  }
@@ -47,6 +47,7 @@ exports.ViroARImageMarker = void 0;
47
47
  const React = __importStar(require("react"));
48
48
  const react_native_1 = require("react-native");
49
49
  const ViroBase_1 = require("../ViroBase");
50
+ const ViroPlatform_1 = require("../Utilities/ViroPlatform");
50
51
  /**
51
52
  * Container for Viro Components anchored to a detected image.
52
53
  */
@@ -67,6 +68,10 @@ class ViroARImageMarker extends ViroBase_1.ViroBase {
67
68
  }
68
69
  };
69
70
  render() {
71
+ if (ViroPlatform_1.isQuest) {
72
+ console.warn("[Viro] ViroARImageMarker is not supported on Quest and will not render.");
73
+ return null;
74
+ }
70
75
  // Uncomment this line to check for misnamed props
71
76
  //checkMisnamedProps("ViroARImageMarker", this.props);
72
77
  let timeToFuse = undefined;
@@ -20,6 +20,6 @@ export declare class ViroARObjectMarker extends ViroBase<Props> {
20
20
  _onAnchorFound(event: NativeSyntheticEvent<ViroARAnchorFoundEvent>): void;
21
21
  _onAnchorUpdated(event: NativeSyntheticEvent<ViroARAnchorUpdatedEvent>): void;
22
22
  _onAnchorRemoved(_event: NativeSyntheticEvent<ViroARAnchorRemovedEvent>): void;
23
- render(): React.JSX.Element;
23
+ render(): React.JSX.Element | null;
24
24
  }
25
25
  export {};
@@ -47,6 +47,7 @@ exports.ViroARObjectMarker = void 0;
47
47
  const ViroBase_1 = require("../ViroBase");
48
48
  const React = __importStar(require("react"));
49
49
  const react_native_1 = require("react-native");
50
+ const ViroPlatform_1 = require("../Utilities/ViroPlatform");
50
51
  /**
51
52
  * Container for Viro Components anchored to a detected object.
52
53
  */
@@ -67,6 +68,10 @@ class ViroARObjectMarker extends ViroBase_1.ViroBase {
67
68
  }
68
69
  }
69
70
  render() {
71
+ if (ViroPlatform_1.isQuest) {
72
+ console.warn("[Viro] ViroARObjectMarker is not supported on Quest and will not render.");
73
+ return null;
74
+ }
70
75
  // Uncomment this line to check for misnamed props
71
76
  //checkMisnamedProps("ViroARObjectMarker", this.props);
72
77
  let timeToFuse = undefined;
@@ -25,6 +25,6 @@ export declare class ViroARPlane extends ViroBase<Props> {
25
25
  _onAnchorFound: (event: NativeSyntheticEvent<ViroARAnchorFoundEvent>) => void;
26
26
  _onAnchorUpdated: (event: NativeSyntheticEvent<ViroARAnchorUpdatedEvent>) => void;
27
27
  _onAnchorRemoved: (_event: NativeSyntheticEvent<ViroARAnchorRemovedEvent>) => void;
28
- render(): React.JSX.Element;
28
+ render(): React.JSX.Element | null;
29
29
  }
30
30
  export {};
@@ -47,6 +47,7 @@ exports.ViroARPlane = void 0;
47
47
  const ViroBase_1 = require("../ViroBase");
48
48
  const React = __importStar(require("react"));
49
49
  const react_native_1 = require("react-native");
50
+ const ViroPlatform_1 = require("../Utilities/ViroPlatform");
50
51
  /**
51
52
  * Container for Viro Components anchored to a detected plane.
52
53
  */
@@ -67,6 +68,10 @@ class ViroARPlane extends ViroBase_1.ViroBase {
67
68
  }
68
69
  };
69
70
  render() {
71
+ if (ViroPlatform_1.isQuest) {
72
+ console.warn("[Viro] ViroARPlane is not supported on Quest and will not render.");
73
+ return null;
74
+ }
70
75
  // Uncomment this line to check for misnamed props
71
76
  //checkMisnamedProps("ViroARPlane", this.props);
72
77
  let timeToFuse = undefined;