Skip to content

Commit

Permalink
Merge pull request #199 from getAlby/task-camera-active
Browse files Browse the repository at this point in the history
fix: toggle camera only when screen is focussed
  • Loading branch information
im-adithya authored Dec 3, 2024
2 parents 93d709b + a24dcc5 commit a24277b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/QRCodeScanner.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useIsFocused } from "@react-navigation/native";
import { Camera } from "expo-camera";
import { PermissionStatus } from "expo-modules-core/src/PermissionsInterface";
import React, { useEffect } from "react";
Expand All @@ -16,6 +17,7 @@ function QRCodeScanner({
onScanned,
startScanning = true,
}: QRCodeScannerProps) {
const isFocused = useIsFocused();
const [isScanning, setScanning] = React.useState(startScanning);
const [isLoading, setLoading] = React.useState(false);
const [permissionStatus, setPermissionStatus] = React.useState(
Expand Down Expand Up @@ -72,7 +74,9 @@ function QRCodeScanner({
</Text>
</View>
)}
{isScanning && <FocusableCamera onScanned={handleScanned} />}
{isScanning && isFocused && (
<FocusableCamera onScanned={handleScanned} />
)}
</>
)}
</View>
Expand Down

0 comments on commit a24277b

Please sign in to comment.