Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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>
);
}
}
47 changes: 47 additions & 0 deletions hooks/useMaxBrightness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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);

useEffect(() => {
const enableBrightness = async () => {
try {
if (previousBrightness.current === null) {
previousBrightness.current = await getBrightnessAsync();
}
await setBrightnessAsync(1);
} catch (error) {
warn("Failed to set brightness:");
}
};

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

enableBrightness();

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

return () => {
subscription.remove();
restoreBrightness();
};
}, []);
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 @@ -52,6 +52,7 @@
"expo-battery": "~10.0.8",
"expo-blur": "~15.0.8",
"expo-build-properties": "~1.0.10",
"expo-brightness": "~14.0.8",
Comment thread
THE-lulu57 marked this conversation as resolved.
Outdated
"expo-camera": "~17.0.10",
"expo-crypto": "~15.0.8",
"expo-dev-client": "~6.0.20",
Expand Down