@artsy/palette-mobile 19.13.0 → 19.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import AsyncStorage from "@react-native-async-storage/async-storage";
3
- import { useAtom } from "jotai";
4
- import { atomWithStorage, createJSONStorage } from "jotai/utils";
5
3
  import { useEffect, useState } from "react";
6
4
  import { Appearance } from "react-native";
7
5
  import { SafeAreaProvider } from "react-native-safe-area-context";
@@ -10,20 +8,34 @@ import { Flex } from "../elements/Flex";
10
8
  import { LinkText, Text } from "../elements/Text";
11
9
  import { ScreenDimensionsProvider } from "../utils/hooks";
12
10
  export const withTheme = (story) => (_jsxs(Theme, { theme: "v3light", children: [_jsx(Text, { color: "red", children: "aaww" }), story()] }));
13
- const atomStorage = createJSONStorage(() => AsyncStorage);
14
- const atomWithAsyncStorage = (key, initialValue) => atomWithStorage(key, initialValue, {
15
- ...atomStorage,
16
- }, {
17
- getOnInit: false,
18
- });
19
- const modeAtom = atomWithAsyncStorage("dark-mode-mode", "system");
11
+ const DARK_MODE_STORAGE_KEY = "dark-mode-mode";
20
12
  export const useDarkModeSwitcher = (story) => {
21
- const [mode, setMode] = useAtom(modeAtom);
13
+ const [mode, setModeState] = useState("system");
22
14
  const [systemMode, setSystemMode] = useState(Appearance.getColorScheme() ?? "light");
15
+ // Load initial value from AsyncStorage on mount
23
16
  useEffect(() => {
24
- const subscription = Appearance.addChangeListener(({ colorScheme }) => void setSystemMode(colorScheme ?? "light"));
17
+ AsyncStorage.getItem(DARK_MODE_STORAGE_KEY)
18
+ .then((value) => {
19
+ if (value && (value === "light" || value === "dark" || value === "system")) {
20
+ setModeState(value);
21
+ }
22
+ })
23
+ .catch((error) => {
24
+ console.error("Failed to load dark mode preference:", error);
25
+ });
26
+ }, []);
27
+ useEffect(() => {
28
+ const subscription = Appearance.addChangeListener(({ colorScheme }) => {
29
+ setSystemMode(colorScheme ?? "light");
30
+ });
25
31
  return () => subscription.remove();
26
32
  }, []);
33
+ const setMode = (newMode) => {
34
+ setModeState(newMode);
35
+ AsyncStorage.setItem(DARK_MODE_STORAGE_KEY, newMode).catch((error) => {
36
+ console.error("Failed to save dark mode preference:", error);
37
+ });
38
+ };
27
39
  const isDarkMode = mode === "dark" || (mode === "system" && systemMode === "dark");
28
40
  const theme = isDarkMode ? "v3dark" : "v3light";
29
41
  return (_jsx(ScreenDimensionsProvider, { children: _jsx(SafeAreaProvider, { children: _jsx(Theme, { theme: theme, children: _jsxs(Flex, { flex: 1, backgroundColor: "background", children: [_jsxs(Flex, { flexDirection: "row", justifyContent: "space-around", children: [_jsxs(Text, { color: "orange", children: ["Dark mode: ", mode, " ", mode === "system" && "(" + systemMode + ")"] }), _jsx(LinkText, { color: "orange", onPress: () => setMode("light"), children: "light" }), _jsx(LinkText, { color: "orange", onPress: () => setMode("dark"), children: "dark" }), _jsx(LinkText, { color: "orange", onPress: () => setMode("system"), children: "system" })] }), story()] }) }) }) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artsy/palette-mobile",
3
- "version": "19.13.0",
3
+ "version": "19.14.0",
4
4
  "description": "Artsy's design system for React Native",
5
5
  "scripts": {
6
6
  "android": "expo run:android --port 8082",
@@ -114,7 +114,6 @@
114
114
  "jest-environment-jsdom": "29.4.2",
115
115
  "jest-extended": "3.2.3",
116
116
  "jest-watch-typeahead": "2.2.2",
117
- "jotai": "^2.15.0",
118
117
  "lint-staged": "13.1.2",
119
118
  "nodemon": "^2.0.20",
120
119
  "patch-package": "^8.0.0",