import {useState} from 'react' import {Alert, View} from 'react-native' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import * as DynamicAppIcon from '@mozzius/expo-dynamic-app-icon' import {type NativeStackScreenProps} from '@react-navigation/native-stack' import {PressableScale} from '#/lib/custom-animations/PressableScale' import {type CommonNavigatorParams} from '#/lib/routes/types' import {useGate} from '#/lib/statsig/statsig' import {isAndroid} from '#/platform/detection' import {AppIconImage} from '#/screens/Settings/AppIconSettings/AppIconImage' import {type AppIconSet} from '#/screens/Settings/AppIconSettings/types' import {useAppIconSets} from '#/screens/Settings/AppIconSettings/useAppIconSets' import {atoms as a, useTheme} from '#/alf' import * as Toggle from '#/components/forms/Toggle' import * as Layout from '#/components/Layout' import {Text} from '#/components/Typography' import {IS_INTERNAL} from '#/env' type Props = NativeStackScreenProps export function AppIconSettingsScreen({}: Props) { const t = useTheme() const {_} = useLingui() const sets = useAppIconSets() const gate = useGate() const [currentAppIcon, setCurrentAppIcon] = useState(() => getAppIconName(DynamicAppIcon.getAppIcon()), ) const onSetAppIcon = (icon: DynamicAppIcon.IconName) => { if (isAndroid) { const next = sets.defaults.find(i => i.id === icon) ?? sets.core.find(i => i.id === icon) Alert.alert( next ? _(msg`Change app icon to "${next.name}"`) : _(msg`Change app icon`), // unfortunately necessary -sfn _(msg`The app will be restarted`), [ { text: _(msg`Cancel`), style: 'cancel', }, { text: _(msg`OK`), onPress: () => { setCurrentAppIcon(setAppIcon(icon)) }, style: 'default', }, ], ) } else { setCurrentAppIcon(setAppIcon(icon)) } } return ( App Icon {sets.defaults.map((icon, i) => ( {icon.name} ))} {( <> Bluesky+ {sets.core.map((icon, i) => ( {icon.name} ))} )} ) } function setAppIcon(icon: DynamicAppIcon.IconName) { if (icon === 'default_light') { return getAppIconName(DynamicAppIcon.setAppIcon(null)) } else { return getAppIconName(DynamicAppIcon.setAppIcon(icon)) } } function getAppIconName(icon: string | false): DynamicAppIcon.IconName { if (!icon || icon === 'DEFAULT') { return 'default_light' } else { return icon as DynamicAppIcon.IconName } } function Group({ children, label, value, onChange, }: { children: React.ReactNode label: string value: DynamicAppIcon.IconName onChange: (value: DynamicAppIcon.IconName) => void }) { return ( { if (vals[0]) onChange(vals[0] as DynamicAppIcon.IconName) }}> {children} ) } function Row({ icon, children, isEnd, }: { icon: AppIconSet children: React.ReactNode isEnd: boolean }) { const t = useTheme() const {_} = useLingui() return ( {({hovered, pressed}) => ( {children} )} ) } function RowText({children}: {children: React.ReactNode}) { const t = useTheme() return ( {children} ) } function AppIcon({icon, size = 50}: {icon: AppIconSet; size: number}) { const {_} = useLingui() return ( { if (isAndroid) { Alert.alert( _(msg`Change app icon to "${icon.name}"`), _(msg`The app will be restarted`), [ { text: _(msg`Cancel`), style: 'cancel', }, { text: _(msg`OK`), onPress: () => { DynamicAppIcon.setAppIcon(icon.id) }, style: 'default', }, ], ) } else { DynamicAppIcon.setAppIcon(icon.id) } }}> ) }