about summary refs log tree commit diff
path: root/src/screens/Settings/AppIconSettings/useCurrentAppIcon.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/screens/Settings/AppIconSettings/useCurrentAppIcon.ts')
-rw-r--r--src/screens/Settings/AppIconSettings/useCurrentAppIcon.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/screens/Settings/AppIconSettings/useCurrentAppIcon.ts b/src/screens/Settings/AppIconSettings/useCurrentAppIcon.ts
new file mode 100644
index 000000000..4bc9b665a
--- /dev/null
+++ b/src/screens/Settings/AppIconSettings/useCurrentAppIcon.ts
@@ -0,0 +1,27 @@
+import {useCallback, useMemo, useState} from 'react'
+import * as DynamicAppIcon from '@mozzius/expo-dynamic-app-icon'
+import {useFocusEffect} from '@react-navigation/native'
+
+import {useAppIconSets} from '#/screens/Settings/AppIconSettings/useAppIconSets'
+
+export function useCurrentAppIcon() {
+  const appIconSets = useAppIconSets()
+  const [currentAppIcon, setCurrentAppIcon] = useState(() =>
+    DynamicAppIcon.getAppIcon(),
+  )
+
+  // refresh current icon when screen is focused
+  useFocusEffect(
+    useCallback(() => {
+      setCurrentAppIcon(DynamicAppIcon.getAppIcon())
+    }, []),
+  )
+
+  return useMemo(() => {
+    return (
+      appIconSets.defaults.find(i => i.id === currentAppIcon) ??
+      appIconSets.core.find(i => i.id === currentAppIcon) ??
+      appIconSets.defaults[0]
+    )
+  }, [appIconSets, currentAppIcon])
+}