Skip to content

Commit 5799125

Browse files
committed
add themeStorageKeyName config
1 parent b010c75 commit 5799125

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

apps/docs/src/content/docs/api/provider.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Provider component is used to wrap your app content and provide the theme contex
1717
| `toast` | <a href='/api/provider#toastconfig'>`ToastConfig`</a> | `{}` | Configuration for toast notifications |
1818
| `i18nConfig` | <a href='/api/provider#i18nconfig'>`I18nConfig`</a> | `undefined` | Internationalization configuration |
1919
| `scrollToHideProps` | <a href='/api/provider#scrolltohideprops'>`ScrollToHideProps`</a> | `undefined` | Configuration for scroll-to-hide behavior |
20+
| `themeStorageKeyName?` | `string` | `undefined` | Configuration for key name storage |
2021

2122
### BottomSheetProps
2223

libs/rnc-theme/src/lib/context/RNCProvider.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ interface ThemeProviderProps {
6969
};
7070
i18nConfig?: I18nConfig;
7171
scrollToHideProps?: ScrollToHideProps;
72+
themeStorageKeyName?: string;
7273
}
7374

7475
export const RNCProvider: React.FC<ThemeProviderProps> = ({
@@ -80,6 +81,7 @@ export const RNCProvider: React.FC<ThemeProviderProps> = ({
8081
toast,
8182
i18nConfig,
8283
scrollToHideProps,
84+
themeStorageKeyName,
8385
}) => {
8486
const [themeMode, setThemeModeState] = useState<ThemeMode>(defaultTheme);
8587
const [customTheme, setCustomTheme] = useState<{
@@ -93,6 +95,7 @@ export const RNCProvider: React.FC<ThemeProviderProps> = ({
9395
const [systemColorScheme, setSystemColorScheme] = useState<ColorSchemeName>(
9496
Appearance.getColorScheme()
9597
);
98+
const themeStorageKey = themeStorageKeyName ?? THEME_STORAGE_KEY;
9699

97100
// Determine if dark mode should be active
98101
const isDark =
@@ -146,7 +149,7 @@ export const RNCProvider: React.FC<ThemeProviderProps> = ({
146149

147150
const loadThemeFromStorage = async () => {
148151
try {
149-
const storedConfig = await AsyncStorage.getItem(THEME_STORAGE_KEY);
152+
const storedConfig = await AsyncStorage.getItem(themeStorageKey);
150153
if (storedConfig) {
151154
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
152155
const config: ThemeConfig = JSON.parse(storedConfig);
@@ -218,7 +221,7 @@ export const RNCProvider: React.FC<ThemeProviderProps> = ({
218221
) => {
219222
try {
220223
const config: ThemeConfig = { mode, customTheme, activePreset: preset };
221-
await AsyncStorage.setItem(THEME_STORAGE_KEY, JSON.stringify(config));
224+
await AsyncStorage.setItem(themeStorageKey, JSON.stringify(config));
222225
} catch (error) {
223226
console.warn('Failed to save theme to storage:', error);
224227
}

0 commit comments

Comments
 (0)