Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(IT Wallet): [SIW-1873] Fix useMaxBrightness flickering on iOS #6466

Merged
merged 2 commits into from
Nov 27, 2024
Merged
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
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
Loading