Skip to content

Commit

Permalink
fix: Fix occasional crash during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Jun 10, 2019
1 parent 562e40a commit b43f87a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/frontend/sharedComponents/CameraView.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Acceleration = { x: number, y: number, z: number };

class CameraView extends React.Component<Props, State> {
cameraRef: { current: any };
subscription: { remove: () => any };
subscription: { remove: () => any } | null;
acceleration: Acceleration;
mounted: boolean;
state = { takingPicture: false, showCamera: true };
Expand All @@ -48,7 +48,7 @@ class CameraView extends React.Component<Props, State> {
componentDidMount() {
this.mounted = true;
Accelerometer.isAvailableAsync().then(motionAvailable => {
if (!motionAvailable) return;
if (!motionAvailable || !this.mounted || this.subscription) return;
Accelerometer.setUpdateInterval(1000);
this.subscription = Accelerometer.addListener(acc => {
this.acceleration = acc;
Expand All @@ -59,6 +59,7 @@ class CameraView extends React.Component<Props, State> {
componentWillUnmount() {
this.mounted = false;
if (this.subscription) this.subscription.remove();
this.subscription = null;
}

handleAddPress = (e: any) => {
Expand Down

0 comments on commit b43f87a

Please sign in to comment.