Skip to content

Commit

Permalink
fix(IT Wallet): [SIW-1873] Fix useMaxBrightness flickering on iOS (#…
Browse files Browse the repository at this point in the history
…6466)

## Short description
On iOS, displaying the QR Code of the Trustmark causes the screen
brightness to flicker. This issue is due to a double animation triggered
by an unexpected `AppState` change.
This PR introduces a check to prevent the double animation, ensuring
smooth screen brightness transitions without flickering.

## List of changes proposed in this pull request
- Added a check on app state change in `useMaxBrigthness`

## How to test
Open the Trustmark QR Code modal on iOS, check that the brightness is
not flickering and reaches the maximum value smoothly
  • Loading branch information
mastro993 authored Nov 27, 2024
1 parent 101473a commit 9c088d8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ts/utils/brightness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function useMaxBrightness({
useSmoothTransition = false,
transitionDuration = DEFAULT_TRANSITION_DURATION
}: UseMaxBrightnessOptions = {}) {
const currentAppState = useRef<AppStateStatus | null>(null);
// Store the initial brightness
const initialBrightness = useRef<number | null>(null);
// Only for Android, store if the app was using auto brightness mode
Expand Down Expand Up @@ -209,11 +210,15 @@ export function useMaxBrightness({
let appStateSubscription: any;

const handleAppStateChange = async (nextAppState: AppStateStatus) => {
if (nextAppState === "active") {
if (nextAppState === "active" && currentAppState.current === "inactive") {
// If the app is becoming active and was previously inactive, set the max brightness
await setMaxBrightness();
} else if (initialBrightness.current !== null) {
} else if (nextAppState !== "active") {
// If the app is becoming inactive, restore the initial brightness
// The app always becomes inactive before becoming background
await restoreInitialBrightness();
}
currentAppState.current = nextAppState;
};

const initialize = async () => {
Expand Down

0 comments on commit 9c088d8

Please sign in to comment.