Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/(features)/(cards)/qrcode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import OnboardingBackButton from "@/components/onboarding/OnboardingBackButton";
import { Services } from "@/stores/account/types";
import Stack from "@/ui/components/Stack";
import Typography from "@/ui/components/Typography";
import { useMaxBrightness } from "@/hooks/useMaxBrightness";

export default function QRCodePage() {

Expand All @@ -35,6 +36,8 @@ export default function QRCodePage() {

const finalTranslation = Dimensions.get("window").height / 2;

useMaxBrightness();

const panGesture = Gesture.Pan()
.onUpdate((e) => {
translationY.value = e.translationY < 0 ? e.translationY / 10 : e.translationY;
Expand Down Expand Up @@ -125,4 +128,4 @@ export default function QRCodePage() {
</BlurView>
</GestureDetector>
);
}
}
65 changes: 65 additions & 0 deletions hooks/useMaxBrightness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { AppState } from "react-native";
import { useEffect, useRef } from "react";
import {setBrightnessAsync, getBrightnessAsync} from "expo-brightness"
import { warn } from "@/utils/logger/logger";

export function useMaxBrightness() {

const previousBrightness = useRef<number | null>(null);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);

useEffect(() => {
let isMounted = true;

const enableBrightness = async () => {
try {
const current = await getBrightnessAsync();

if (!isMounted) return;

if (previousBrightness.current === null) {
previousBrightness.current = current
}
await setBrightnessAsync(1);
} catch (error) {
warn("Failed to set brightness");
}
};

const restoreBrightness = async () => {
try {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
timeoutRef.current = null;
}
if (previousBrightness.current !== null) {
await setBrightnessAsync(previousBrightness.current);
}
} catch (error) {
warn("Failed to restore brightness");
}
};

timeoutRef.current = setTimeout(() => {
if (isMounted) {
enableBrightness();
}
}, 100);

const subscription = AppState.addEventListener("change", (nextAppState) => {
if (nextAppState === "inactive" || nextAppState === "background" ) {
restoreBrightness();
} else if (nextAppState === "active") {
timeoutRef.current = setTimeout(() => {
if (isMounted) enableBrightness();
}, 100);
}
});

return () => {
isMounted = false;
restoreBrightness();
subscription.remove();
};
}, []);
Comment thread
THE-lulu57 marked this conversation as resolved.
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"expo-battery": "~55.0.11",
"expo-blur": "~55.0.12",
"expo-build-properties": "~55.0.11",
"expo-brightness": "~55.0.12",
"expo-camera": "~55.0.13",
"expo-crypto": "~55.0.12",
"expo-dev-client": "~55.0.22",
Expand Down