Skip to content

Commit

Permalink
fix: optimise augmented reality
Browse files Browse the repository at this point in the history
- added `totalMemory` value to `device.js` to see the `RAM` information of the device and
  used `totalMemory` in `expo-device` package
- added `GB_TO_BYTES` section to `costs.js` because the `totalMemory` property gives us RAM
  in bytes and therefore we need to know gb in bytes
- removed `spot` and `quad` (shadow) to optimise AR for devices with less than 2 gb of RAM

SVA-1073
  • Loading branch information
ardasnturk committed Aug 2, 2023
1 parent 5a3bae6 commit 71b3f00
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/augmentedReality/AugmentedRealityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import {
import PropTypes from 'prop-types';
import React, { useContext, useEffect } from 'react';

import { colors, texts } from '../../config';
import { colors, consts, device, texts } from '../../config';
import { SettingsContext } from '../../SettingsProvider';

const { GB_TO_BYTES } = consts;

export const AugmentedRealityView = ({ sceneNavigator }) => {
const {
isObjectLoading,
Expand Down Expand Up @@ -164,7 +166,7 @@ const ViroSoundAnd3DObject = (item) => {
/>
))}

{object?.spot && (
{object?.spot && device.totalMemory > GB_TO_BYTES[2] && (
<ViroSpotLight
direction={object.spot.direction}
innerAngle={object.spot.innerAngle}
Expand All @@ -179,7 +181,7 @@ const ViroSoundAnd3DObject = (item) => {
/>
)}

{object?.quad && (
{object?.quad && device.totalMemory > GB_TO_BYTES[2] && (
<ViroQuad
height={object.quad.height}
position={object.quad.position}
Expand Down
7 changes: 7 additions & 0 deletions src/config/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export const consts = {
FULL_SCREEN_MAX_WIDTH: 428
},

// this section has been added to optimise AR on low RAM devices and to prevent some features of AR from being used
GB_TO_BYTES: {
1: 1073741824,
2: 2147483648,
3: 3221225472
},

// the image aspect ratio can be overwritten by a global setting `imageAspectRatio`
// from the server in src/index.js
IMAGE_ASPECT_RATIO: {
Expand Down
2 changes: 2 additions & 0 deletions src/config/device.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Dimensions, Platform } from 'react-native';
import { totalMemory } from 'expo-device';

export const device = {
height: Dimensions.get('window').height,
platform: Platform.OS,
totalMemory,
width: Dimensions.get('window').width
};

0 comments on commit 71b3f00

Please sign in to comment.