summaryrefslogtreecommitdiffstats
path: root/hooks
diff options
context:
space:
mode:
authorjciespuertodelacruz <jc.iespuertodelacruz@gmx.es>2026-01-20 08:49:52 +0000
committerjciespuertodelacruz <jc.iespuertodelacruz@gmx.es>2026-01-20 08:49:52 +0000
commitc6f2b6f85d151d6d2a2cc68eb05edd7a1e448106 (patch)
tree1080219bee426d5d1372da6c31f138482c1544d7 /hooks
Initial commit
Generated by create-expo-app 3.5.3.
Diffstat (limited to 'hooks')
-rw-r--r--hooks/use-color-scheme.ts1
-rw-r--r--hooks/use-color-scheme.web.ts21
-rw-r--r--hooks/use-theme-color.ts21
3 files changed, 43 insertions, 0 deletions
diff --git a/hooks/use-color-scheme.ts b/hooks/use-color-scheme.ts
new file mode 100644
index 0000000..17e3c63
--- /dev/null
+++ b/hooks/use-color-scheme.ts
@@ -0,0 +1 @@
+export { useColorScheme } from 'react-native';
diff --git a/hooks/use-color-scheme.web.ts b/hooks/use-color-scheme.web.ts
new file mode 100644
index 0000000..7eb1c1b
--- /dev/null
+++ b/hooks/use-color-scheme.web.ts
@@ -0,0 +1,21 @@
+import { useEffect, useState } from 'react';
+import { useColorScheme as useRNColorScheme } from 'react-native';
+
+/**
+ * To support static rendering, this value needs to be re-calculated on the client side for web
+ */
+export function useColorScheme() {
+ const [hasHydrated, setHasHydrated] = useState(false);
+
+ useEffect(() => {
+ setHasHydrated(true);
+ }, []);
+
+ const colorScheme = useRNColorScheme();
+
+ if (hasHydrated) {
+ return colorScheme;
+ }
+
+ return 'light';
+}
diff --git a/hooks/use-theme-color.ts b/hooks/use-theme-color.ts
new file mode 100644
index 0000000..0cbc3a6
--- /dev/null
+++ b/hooks/use-theme-color.ts
@@ -0,0 +1,21 @@
+/**
+ * Learn more about light and dark modes:
+ * https://docs.expo.dev/guides/color-schemes/
+ */
+
+import { Colors } from '@/constants/theme';
+import { useColorScheme } from '@/hooks/use-color-scheme';
+
+export function useThemeColor(
+ props: { light?: string; dark?: string },
+ colorName: keyof typeof Colors.light & keyof typeof Colors.dark
+) {
+ const theme = useColorScheme() ?? 'light';
+ const colorFromProps = props[theme];
+
+ if (colorFromProps) {
+ return colorFromProps;
+ } else {
+ return Colors[theme][colorName];
+ }
+}