Skip to content

Commit

Permalink
Merge pull request #52083 from QichenZhu/fix/51821
Browse files Browse the repository at this point in the history
Fix web camera not loading
  • Loading branch information
yuwenmemon authored Nov 7, 2024
2 parents 494211d + bbdce8c commit d203c4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {useIsFocused} from '@react-navigation/native';
import React from 'react';
import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import type {Camera} from 'react-native-vision-camera';
import Webcam from 'react-webcam';
import useTabNavigatorFocus from '@hooks/useTabNavigatorFocus';
import type {NavigationAwareCameraProps} from './types';

// Wraps a camera that will only be active when the tab is focused or as soon as it starts to become focused.
function WebCamera({torchOn, onTorchAvailability, cameraTabIndex, ...props}: NavigationAwareCameraProps, ref: ForwardedRef<Webcam | Camera>) {
const shouldShowCamera = useTabNavigatorFocus({
tabIndex: cameraTabIndex,
});
const shouldShowCamera = useIsFocused();

if (!shouldShowCamera) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useIsFocused} from '@react-navigation/native';
import {Str} from 'expensify-common';
import React, {useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState} from 'react';
import {ActivityIndicator, PanResponder, PixelRatio, View} from 'react-native';
Expand All @@ -24,7 +25,6 @@ import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalD
import useLocalize from '@hooks/useLocalize';
import usePolicy from '@hooks/usePolicy';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTabNavigatorFocus from '@hooks/useTabNavigatorFocus';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Browser from '@libs/Browser';
Expand Down Expand Up @@ -93,7 +93,7 @@ function IOURequestStepScan({

const [videoConstraints, setVideoConstraints] = useState<MediaTrackConstraints>();
const tabIndex = 1;
const isTabActive = useTabNavigatorFocus({tabIndex});
const isTabActive = useIsFocused();

const isEditing = action === CONST.IOU.ACTION.EDIT;
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction);
Expand Down

0 comments on commit d203c4d

Please sign in to comment.