Skip to content

Commit a380420

Browse files
fix: fix isARSupportedOnDevice (#262)
* fix: fix isARSupportedOnDevice The React code wasn't working and wasn't returning a value properly. This commit wraps the code in a promise so it can be used asynchronously. * chore: version bump 2.23.3
1 parent eac9454 commit a380420

File tree

7 files changed

+103
-64
lines changed

7 files changed

+103
-64
lines changed

Diff for: components/Utilities/ViroUtils.tsx

+48-29
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,54 @@ export function polarToCartesianActual(polarcoords: number[]) {
6767
}
6868

6969
import { Platform, NativeModules } from "react-native";
70-
export function isARSupportedOnDevice(
71-
notSupportedCallback: (result?: string | Error) => void,
72-
supportedCallback: (result?: string | Error) => void
73-
) {
74-
if (Platform.OS == "ios") {
75-
NativeModules.VRTARUtils.isARSupported((error: Error, result: any) => {
76-
if (result.isARSupported == true) {
77-
{
78-
supportedCallback();
79-
}
80-
} else {
81-
{
82-
notSupportedCallback();
70+
71+
export interface ViroiOSArSupportResponse {
72+
isARSupported: boolean;
73+
}
74+
75+
export type ViroAndroidArSupportResponse =
76+
/**
77+
* The device is <b>supported</b> by ARCore.
78+
*/
79+
| "SUPPORTED"
80+
/**
81+
* The device is <b>unsupported</b> by ARCore.
82+
*/
83+
| "UNSUPPORTED"
84+
/**
85+
* ARCore support is <b>unknown</b> for this device.
86+
*/
87+
| "UNKNOWN"
88+
/**
89+
* ARCore is still checking for support. This is a temporary state, and the application should
90+
* check again soon.
91+
*/
92+
| "TRANSIENT";
93+
94+
export interface ViroARSupportResponse {
95+
isARSupported: boolean;
96+
}
97+
98+
export function isARSupportedOnDevice() {
99+
return new Promise<ViroARSupportResponse>((resolve, reject) => {
100+
if (Platform.OS == "ios") {
101+
NativeModules.VRTARUtils.isARSupported(
102+
(error: Error, result: ViroiOSArSupportResponse) => {
103+
console.log("[isARSupportedOnDevice]: iOS", { error, result });
104+
if (error) reject(error);
105+
if (result) resolve(result);
106+
reject("AR Support Unknown.");
83107
}
84-
}
85-
});
86-
} else {
87-
NativeModules.VRTARSceneNavigatorModule.isARSupportedOnDevice(
88-
(result: any) => {
89-
if (result == "SUPPORTED") {
90-
{
91-
supportedCallback();
92-
}
93-
} else {
94-
{
95-
notSupportedCallback(result);
96-
}
108+
);
109+
} else {
110+
NativeModules.VRTARSceneNavigatorModule.isARSupportedOnDevice(
111+
(result: ViroAndroidArSupportResponse) => {
112+
console.log("[isARSupportedOnDevice]: Android", { result });
113+
if (result == "SUPPORTED") resolve({ isARSupported: true });
114+
if (result) reject(new Error(result));
115+
reject("AR Support Unknown.");
97116
}
98-
}
99-
);
100-
}
117+
);
118+
}
119+
});
101120
}

Diff for: dist/components/Utilities/ViroUtils.d.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,28 @@ export declare function polarToCartesian(polarcoords: number[]): number[];
2828
* phi - the yz-plane angle starting from y = 0 degrees
2929
*/
3030
export declare function polarToCartesianActual(polarcoords: number[]): number[];
31-
export declare function isARSupportedOnDevice(notSupportedCallback: (result?: string | Error) => void, supportedCallback: (result?: string | Error) => void): void;
31+
export interface ViroiOSArSupportResponse {
32+
isARSupported: boolean;
33+
}
34+
export type ViroAndroidArSupportResponse =
35+
/**
36+
* The device is <b>supported</b> by ARCore.
37+
*/
38+
"SUPPORTED"
39+
/**
40+
* The device is <b>unsupported</b> by ARCore.
41+
*/
42+
| "UNSUPPORTED"
43+
/**
44+
* ARCore support is <b>unknown</b> for this device.
45+
*/
46+
| "UNKNOWN"
47+
/**
48+
* ARCore is still checking for support. This is a temporary state, and the application should
49+
* check again soon.
50+
*/
51+
| "TRANSIENT";
52+
export interface ViroARSupportResponse {
53+
isARSupported: boolean;
54+
}
55+
export declare function isARSupportedOnDevice(): Promise<ViroARSupportResponse>;

Diff for: dist/components/Utilities/ViroUtils.js

+23-29
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,28 @@ function polarToCartesianActual(polarcoords) {
6262
}
6363
exports.polarToCartesianActual = polarToCartesianActual;
6464
const react_native_1 = require("react-native");
65-
function isARSupportedOnDevice(notSupportedCallback, supportedCallback) {
66-
if (react_native_1.Platform.OS == "ios") {
67-
react_native_1.NativeModules.VRTARUtils.isARSupported((error, result) => {
68-
if (result.isARSupported == true) {
69-
{
70-
supportedCallback();
71-
}
72-
}
73-
else {
74-
{
75-
notSupportedCallback();
76-
}
77-
}
78-
});
79-
}
80-
else {
81-
react_native_1.NativeModules.VRTARSceneNavigatorModule.isARSupportedOnDevice((result) => {
82-
if (result == "SUPPORTED") {
83-
{
84-
supportedCallback();
85-
}
86-
}
87-
else {
88-
{
89-
notSupportedCallback(result);
90-
}
91-
}
92-
});
93-
}
65+
function isARSupportedOnDevice() {
66+
return new Promise((resolve, reject) => {
67+
if (react_native_1.Platform.OS == "ios") {
68+
react_native_1.NativeModules.VRTARUtils.isARSupported((error, result) => {
69+
console.log("[isARSupportedOnDevice]: iOS", { error, result });
70+
if (error)
71+
reject(error);
72+
if (result)
73+
resolve(result);
74+
reject("AR Support Unknown.");
75+
});
76+
}
77+
else {
78+
react_native_1.NativeModules.VRTARSceneNavigatorModule.isARSupportedOnDevice((result) => {
79+
console.log("[isARSupportedOnDevice]: Android", { result });
80+
if (result == "SUPPORTED")
81+
resolve({ isARSupported: true });
82+
if (result)
83+
reject(new Error(result));
84+
reject("AR Support Unknown.");
85+
});
86+
}
87+
});
9488
}
9589
exports.isARSupportedOnDevice = isARSupportedOnDevice;

Diff for: dist/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ import { ViroVRSceneNavigator } from "./components/ViroVRSceneNavigator";
5252
import { Viro3DSceneNavigator } from "./components/Viro3DSceneNavigator";
5353
import { ViroTextStyle } from "./components/Styles/ViroTextStyle";
5454
import { ViroStyle } from "./components/Styles/ViroStyle";
55-
import { polarToCartesian, polarToCartesianActual, isARSupportedOnDevice } from "./components/Utilities/ViroUtils";
55+
import { polarToCartesian, polarToCartesianActual, isARSupportedOnDevice, ViroARSupportResponse } from "./components/Utilities/ViroUtils";
5656
import { ViroARCamera } from "./components/AR/ViroARCamera";
5757
import { ViroHoverEvent, ViroClickEvent, ViroClickStateEvent, ViroTouchEvent, ViroScrollEvent, ViroSwipeEvent, ViroFuseEvent, ViroPinchEvent, ViroRotateEvent, ViroDragEvent, ViroPlatformEvent, ViroCollisionEvent, ViroPlatformInfo, ViroCameraTransformEvent, ViroPlatformUpdateEvent, ViroCameraTransform, ViroExitViroEvent, ViroErrorEvent, ViroAnimationStartEvent, ViroAnimationFinishEvent, ViroLoadStartEvent, ViroLoadEndEvent, ViroLoadErrorEvent, ViroVideoBufferStartEvent, ViroVideoBufferEndEvent, ViroVideoUpdateTimeEvent, ViroVideoErrorEvent, ViroVideoFinishEvent, ViroAnimatedComponentStartEvent, ViroAnimatedComponentFinishEvent, ViroARAnchorRemovedEvent, ViroARAnchorUpdatedEvent, ViroARAnchorFoundEvent, ViroAnchor, ViroAnchorFoundMap, ViroAnchorUpdatedMap, ViroPlaneUpdatedMap, ViroPlaneUpdatedEvent, ViroARPlaneSizes, ViroCameraARHitTestEvent, ViroCameraARHitTest, ViroARHitTestResult, ViroARPointCloudUpdateEvent, ViroARPointCloud, ViroTrackingUpdatedEvent, ViroTrackingState, ViroTrackingReason, ViroAmbientLightUpdateEvent, ViroAmbientLightInfo, ViroWorldOrigin, ViroNativeTransformUpdateEvent, ViroControllerStatusEvent, ViroControllerStatus, ViroPortalEnterEvent, ViroPortalExitEvent, ViroSoundFinishEvent, ViroPinchStateTypes, ViroClickStateTypes, ViroRotateStateTypes } from "./components/Types/ViroEvents";
5858
import { ViroSurface } from "./components/ViroSurface";
5959
import { ViroSceneNavigator } from "./components/ViroSceneNavigator";
60-
export { ViroARImageMarker, ViroARObjectMarker, ViroARTrackingTargets, ViroARPlane, ViroARPlaneSelector, ViroARScene, ViroARSceneNavigator, ViroBox, ViroButton, ViroCamera, ViroController, ViroDirectionalLight, ViroFlexView, ViroGeometry, ViroLightingEnvironment, ViroImage, ViroMaterials, ViroARCamera, ViroMaterialVideo, ViroNode, ViroOmniLight, ViroOrbitCamera, ViroParticleEmitter, ViroPolygon, ViroPolyline, ViroPortal, ViroPortalScene, ViroQuad, ViroScene, ViroSurface, ViroSceneNavigator, ViroSkyBox, ViroAnimations, Viro3DObject, Viro360Image, Viro360Video, ViroAnimatedImage, ViroAmbientLight, ViroAnimatedComponent, ViroSound, ViroSoundField, ViroSpatialSound, ViroSphere, ViroSpinner, ViroSpotLight, ViroText, ViroVideo, ViroVRSceneNavigator, Viro3DSceneNavigator, ViroARTrackingReasonConstants, ViroRecordingErrorConstants, ViroTrackingStateConstants, polarToCartesian, polarToCartesianActual, isARSupportedOnDevice, ViroHoverEvent, ViroClickEvent, ViroClickStateEvent, ViroClickStateTypes, ViroTouchEvent, ViroScrollEvent, ViroSwipeEvent, ViroFuseEvent, ViroPinchEvent, ViroPinchStateTypes, ViroRotateEvent, ViroRotateStateTypes, ViroDragEvent, ViroPlatformEvent, ViroCollisionEvent, ViroPlatformInfo, ViroCameraTransformEvent, ViroPlatformUpdateEvent, ViroCameraTransform, ViroExitViroEvent, ViroErrorEvent, ViroAnimationStartEvent, ViroAnimationFinishEvent, ViroLoadStartEvent, ViroLoadEndEvent, ViroLoadErrorEvent, ViroVideoBufferStartEvent, ViroVideoBufferEndEvent, ViroVideoUpdateTimeEvent, ViroVideoErrorEvent, ViroVideoFinishEvent, ViroAnimatedComponentStartEvent, ViroAnimatedComponentFinishEvent, ViroARAnchorRemovedEvent, ViroARAnchorUpdatedEvent, ViroARAnchorFoundEvent, ViroAnchor, ViroAnchorFoundMap, ViroAnchorUpdatedMap, ViroPlaneUpdatedMap, ViroPlaneUpdatedEvent, ViroARPlaneSizes, ViroCameraARHitTestEvent, ViroCameraARHitTest, ViroARHitTestResult, ViroARPointCloudUpdateEvent, ViroARPointCloud, ViroTrackingUpdatedEvent, ViroTrackingState, ViroTrackingReason, ViroAmbientLightUpdateEvent, ViroAmbientLightInfo, ViroWorldOrigin, ViroNativeTransformUpdateEvent, ViroControllerStatusEvent, ViroControllerStatus, ViroPortalEnterEvent, ViroPortalExitEvent, ViroSoundFinishEvent, ViroTextStyle, ViroStyle, };
60+
export { ViroARImageMarker, ViroARObjectMarker, ViroARTrackingTargets, ViroARPlane, ViroARPlaneSelector, ViroARScene, ViroARSceneNavigator, ViroBox, ViroButton, ViroCamera, ViroController, ViroDirectionalLight, ViroFlexView, ViroGeometry, ViroLightingEnvironment, ViroImage, ViroMaterials, ViroARCamera, ViroMaterialVideo, ViroNode, ViroOmniLight, ViroOrbitCamera, ViroParticleEmitter, ViroPolygon, ViroPolyline, ViroPortal, ViroPortalScene, ViroQuad, ViroScene, ViroSurface, ViroSceneNavigator, ViroSkyBox, ViroAnimations, Viro3DObject, Viro360Image, Viro360Video, ViroAnimatedImage, ViroAmbientLight, ViroAnimatedComponent, ViroSound, ViroSoundField, ViroSpatialSound, ViroSphere, ViroSpinner, ViroSpotLight, ViroText, ViroVideo, ViroVRSceneNavigator, Viro3DSceneNavigator, ViroARTrackingReasonConstants, ViroRecordingErrorConstants, ViroTrackingStateConstants, polarToCartesian, polarToCartesianActual, isARSupportedOnDevice, ViroARSupportResponse, ViroHoverEvent, ViroClickEvent, ViroClickStateEvent, ViroClickStateTypes, ViroTouchEvent, ViroScrollEvent, ViroSwipeEvent, ViroFuseEvent, ViroPinchEvent, ViroPinchStateTypes, ViroRotateEvent, ViroRotateStateTypes, ViroDragEvent, ViroPlatformEvent, ViroCollisionEvent, ViroPlatformInfo, ViroCameraTransformEvent, ViroPlatformUpdateEvent, ViroCameraTransform, ViroExitViroEvent, ViroErrorEvent, ViroAnimationStartEvent, ViroAnimationFinishEvent, ViroLoadStartEvent, ViroLoadEndEvent, ViroLoadErrorEvent, ViroVideoBufferStartEvent, ViroVideoBufferEndEvent, ViroVideoUpdateTimeEvent, ViroVideoErrorEvent, ViroVideoFinishEvent, ViroAnimatedComponentStartEvent, ViroAnimatedComponentFinishEvent, ViroARAnchorRemovedEvent, ViroARAnchorUpdatedEvent, ViroARAnchorFoundEvent, ViroAnchor, ViroAnchorFoundMap, ViroAnchorUpdatedMap, ViroPlaneUpdatedMap, ViroPlaneUpdatedEvent, ViroARPlaneSizes, ViroCameraARHitTestEvent, ViroCameraARHitTest, ViroARHitTestResult, ViroARPointCloudUpdateEvent, ViroARPointCloud, ViroTrackingUpdatedEvent, ViroTrackingState, ViroTrackingReason, ViroAmbientLightUpdateEvent, ViroAmbientLightInfo, ViroWorldOrigin, ViroNativeTransformUpdateEvent, ViroControllerStatusEvent, ViroControllerStatus, ViroPortalEnterEvent, ViroPortalExitEvent, ViroSoundFinishEvent, ViroTextStyle, ViroStyle, };

Diff for: index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
polarToCartesian,
6262
polarToCartesianActual,
6363
isARSupportedOnDevice,
64+
ViroARSupportResponse,
6465
} from "./components/Utilities/ViroUtils";
6566
import { ViroARCamera } from "./components/AR/ViroARCamera";
6667
import {
@@ -185,6 +186,7 @@ export {
185186
polarToCartesianActual,
186187
isARSupportedOnDevice,
187188
// Types
189+
ViroARSupportResponse,
188190
ViroHoverEvent,
189191
ViroClickEvent,
190192
ViroClickStateEvent,

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"main": "dist/index.js",
44
"module": "dist/index.js",
55
"types": "dist/index.d.ts",
6-
"version": "2.23.2",
6+
"version": "2.23.3",
77
"license": "MIT",
88
"publishConfig": {
99
"registry": "https://registry.npmjs.org/"

0 commit comments

Comments
 (0)