about summary refs log tree commit diff
path: root/src/screens/Settings/AppIconSettings/useCurrentAppIcon.ts
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-12-11 22:33:45 +0000
committerGitHub <noreply@github.com>2024-12-11 22:33:45 +0000
commite49dad28896695fc6396ba704a94d3e459711f1a (patch)
tree99a702c4a1794d8ae4223fbdcbec38fc9ece69b6 /src/screens/Settings/AppIconSettings/useCurrentAppIcon.ts
parent69f22b9dba41987763310c1adc4ac87d58d63334 (diff)
downloadvoidsky-e49dad28896695fc6396ba704a94d3e459711f1a.tar.zst
Nicer app icon screen (#6972)
* wip exploration

* list format instead of grid

* fix normalising default name

* adjust margins

* Rework the app icon link

* Decrease app icon size

* Adjust some spacing

* Move some things around to fix web errors

* Fix pathname

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Co-authored-by: Eric Bailey <git@esb.lol>
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])
+}