Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 206x 206x 206x 2x 1x 6x 6x 6x 975x 5x 3x 1x | import { create } from "zustand";
import AsyncStorage from "@react-native-async-storage/async-storage";
interface DisplaySettingsState {
brightness: number; // 0-100
autoBrightness: boolean;
darkMode: boolean;
colorIntensity: number; // 0-100
screenTimeout: "30s" | "1m" | "2m";
displayZoom: "Standard" | "Large";
setBrightness: (value: number) => void;
setAutoBrightness: (value: boolean) => void;
setDarkMode: (value: boolean) => void;
setColorIntensity: (value: number) => void;
setScreenTimeout: (value: "30s" | "1m" | "2m") => void;
setDisplayZoom: (value: "Standard" | "Large") => void;
hydrateFromStorage: () => Promise<void>;
}
const STORAGE_KEY = "displaySettings.v1";
export const useDisplaySettingsStore = create<DisplaySettingsState>(
(set, get) => ({
brightness: 75,
autoBrightness: true,
darkMode: false,
colorIntensity: 100,
screenTimeout: "2m",
displayZoom: "Standard",
setBrightness: (brightness) =>
set((state) => {
const next = { ...state, brightness };
void persist(next);
return next;
}),
setAutoBrightness: (autoBrightness) =>
set((state) => {
const next = { ...state, autoBrightness };
void persist(next);
return next;
}),
setDarkMode: (darkMode) =>
set((state) => {
const next = { ...state, darkMode };
void persist(next);
return next;
}),
setColorIntensity: (colorIntensity) =>
set((state) => {
const next = { ...state, colorIntensity };
void persist(next);
return next;
}),
setScreenTimeout: (screenTimeout) =>
set((state) => {
const next = { ...state, screenTimeout };
void persist(next);
return next;
}),
setDisplayZoom: (displayZoom) =>
set((state) => {
const next = { ...state, displayZoom };
void persist(next);
return next;
}),
hydrateFromStorage: async () => {
try {
const raw = await AsyncStorage.getItem(STORAGE_KEY);
if (!raw) return;
const parsed = JSON.parse(raw);
set((state) => ({
...state,
...parsed,
}));
} catch {
// ignore hydration issues
}
},
}),
);
async function persist(state: DisplaySettingsState) {
const {
brightness,
autoBrightness,
darkMode,
colorIntensity,
screenTimeout,
displayZoom,
} = state;
try {
await AsyncStorage.setItem(
STORAGE_KEY,
JSON.stringify({
brightness,
autoBrightness,
darkMode,
colorIntensity,
screenTimeout,
displayZoom,
}),
);
} catch {
// best-effort
}
}
export function useDisplaySettings() {
return useDisplaySettingsStore();
}
export function getBrightnessLabel(value: number): string {
if (value <= 33) return "Low";
if (value >= 75) return "High";
return "Medium";
}
|