Skip to content

Commit

Permalink
fix(qrcode): restore brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
raphckrman committed Dec 19, 2024
1 parent 78f9aa7 commit 87912b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/views/account/Restaurant/Modals/QrCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TouchableOpacity,
StyleSheet,
ScrollView, Platform,
AppState,
} from "react-native";
import { DeviceMotion } from "expo-sensors";
import { SafeAreaView } from "react-native-safe-area-context";
Expand Down Expand Up @@ -59,6 +60,29 @@ const RestaurantQrCode: Screen<"RestaurantQrCode"> = ({ route, navigation }) =>
const [oldBrightness, setOldBrightness] = useState<number>(0.5);

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

const handleAppStateChange = async (nextAppState: string) => {
if (nextAppState === "background" || nextAppState === "inactive") {
if (isActive) {
isActive = false;
await Brightness.setBrightnessAsync(oldBrightness);
}
} else if (nextAppState === "active") {
isActive = true;
await Brightness.setBrightnessAsync(1);
}
};

const appStateSubscription = AppState.addEventListener(
"change",
handleAppStateChange
);

const navigationSubscription = navigation.addListener("beforeRemove", () => {
Brightness.setBrightnessAsync(oldBrightness);
});

(async () => {
if (Platform.OS === "android") {
const { status } = await Brightness.requestPermissionsAsync();
Expand All @@ -73,7 +97,11 @@ const RestaurantQrCode: Screen<"RestaurantQrCode"> = ({ route, navigation }) =>
await Brightness.setBrightnessAsync(1);
} catch (e) { console.warn("Brightness error:", e); }
})();
return () => { Brightness.setBrightnessAsync(oldBrightness); };
return () => {
appStateSubscription.remove();
navigationSubscription();
Brightness.setBrightnessAsync(oldBrightness);
};
}, [navigation, oldBrightness]);


Expand Down
3 changes: 3 additions & 0 deletions src/views/settings/ExternalAccount/Turboself.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const ExternalTurboselfLogin: Screen<"ExternalTurboselfLogin"> = ({ navigation }
} catch (error) {
if (error instanceof Error) {
setError(error.message);
if (error.message == "401: {\"statusCode\":401,\"message\":\"Accès interdit\"}") {
setError("Nom d'utilisateur ou mot de passe incorrect");
};
}
else {
setError("Une erreur est survenue lors de la connexion.");
Expand Down

0 comments on commit 87912b8

Please sign in to comment.