UNPKG

onboardsync-react-native

Version:

Expo SDK for OnboardSync - Remote onboarding configuration platform with A/B testing

57 lines (47 loc) 2.02 kB
import { StatusBar, Platform, StatusBarStyle } from 'react-native'; import { ColorUtils } from './colorUtils'; export class StatusBarHelper { private static originalStyle: StatusBarStyle | null = null; private static originalBackgroundColor: string | null = null; private static originalTranslucent: boolean | null = null; static saveCurrentState(): void { if (Platform.OS === 'ios') { // iOS doesn't have backgroundColor or translucent this.originalStyle = StatusBar.currentHeight as unknown as StatusBarStyle || 'dark-content'; } else { // Android specific this.originalStyle = 'dark-content'; // Default this.originalBackgroundColor = 'transparent'; this.originalTranslucent = true; } } static updateForColor(backgroundColor: string): void { const isDark = ColorUtils.isColorDark(backgroundColor); const style: StatusBarStyle = isDark ? 'light-content' : 'dark-content'; console.log(`[OnboardSync] Updating status bar - Background: ${backgroundColor}, Style: ${style}`); StatusBar.setBarStyle(style, true); if (Platform.OS === 'android') { StatusBar.setBackgroundColor(backgroundColor, true); StatusBar.setTranslucent(false); } } static updateForTheme(style: 'light' | 'dark'): void { const barStyle: StatusBarStyle = style === 'light' ? 'light-content' : 'dark-content'; console.log(`[OnboardSync] Updating status bar for theme: ${style} -> ${barStyle}`); StatusBar.setBarStyle(barStyle, true); } static restore(): void { if (this.originalStyle) { StatusBar.setBarStyle(this.originalStyle, true); } if (Platform.OS === 'android') { if (this.originalBackgroundColor) { StatusBar.setBackgroundColor(this.originalBackgroundColor, true); } if (this.originalTranslucent !== null) { StatusBar.setTranslucent(this.originalTranslucent); } } console.log('[OnboardSync] Restored original status bar settings'); } }