Ability to set status and bottom navigation bar colors on Androids #162
Replies: 8 comments 32 replies
-
Sure you did! I'm interested, I will propose some api soon, maybe it will land in 2.6.0, who knows! I'm looking forward for such ideas 🙏 |
Beta Was this translation helpful? Give feedback.
-
Thanks @jpudysz! Looking forward to it! |
Beta Was this translation helpful? Give feedback.
-
@efstathiosntonas I have something for you (still WIP) 😉: UnistylesRuntime.statusBar.setColor(string || undefined)
UnistylesRuntime.navigationBar.setColor(string || undefined)
For now supports HEX colors, undefined = set default color Screen.Recording.2024-03-27.at.11.02.55.mov |
Beta Was this translation helpful? Give feedback.
-
AMAZING!! what a relief to see an easy API for this.... |
Beta Was this translation helpful? Give feedback.
-
Released with 2.6.0-rc.0, you can install it with yarn add react-native-unistyles@next |
Beta Was this translation helpful? Give feedback.
-
@jpudysz should we add this too: https://github.com/pnthach95/react-native-root-view-background ? |
Beta Was this translation helpful? Give feedback.
-
@jpudysz hi, just saw you released 2.6.0 so closing this as resolved. Did you had the chance to read my comments on the PR? I encountered crashes while setting the navbar color (haven't tested status bar). |
Beta Was this translation helpful? Give feedback.
-
i use this crazy hook: useEffect(() => {
(async function initTheme() {
const autoThemeMode = await AsyncStorage.getItem("autoThemeMode");
const themeMode = await AsyncStorage.getItem("themeMode");
if (!autoThemeMode && !themeMode) {
// setNavigationColor(theme);
UnistylesRuntime.setTheme(theme);
UnistylesRuntime.navigationBar.setColor(
theme === "dark" ? "#17181C" : mode === "highContrast" ? "#000000" : "#FFFFFF"
);
return setMode(theme);
}
if (autoThemeMode === "true") {
const m =
themeMode === "highContrast" && theme === "dark" ? "highContrast" : theme;
UnistylesRuntime.navigationBar.setColor(
m === "dark" ? "#17181C" : m === "highContrast" ? "#000000" : "#FFFFFF"
);
// UnistylesRuntime.setTheme(m);
return setMode(m);
}
if (autoThemeMode === "true") {
const m = themeMode === "dark" && theme === "dark" ? "dark" : theme;
// setNavigationColor(m);
UnistylesRuntime.setTheme(m);
UnistylesRuntime.navigationBar.setColor(
m === "dark" ? "#17181C" : mode === "highContrast" ? "#000000" : "#FFFFFF"
);
return setMode(m);
}
if (!themeMode) {
// setNavigationColor(theme);
UnistylesRuntime.setTheme(theme);
UnistylesRuntime.navigationBar.setColor(theme === "dark" ? "#17181C" : "#FFFFFF");
return setMode(theme);
}
if (
(themeMode === "highContrast" && theme === "dark") ||
(themeMode === "highContrast" && theme === "light")
) {
// setNavigationColor("highContrast");
UnistylesRuntime.setTheme("highContrast");
UnistylesRuntime.navigationBar.setColor("#000000");
return setMode("highContrast");
}
if (themeMode === "dark") {
//setNavigationColor("dark");
UnistylesRuntime.setTheme("dark");
UnistylesRuntime.navigationBar.setColor("#17181C");
return setMode("dark");
}
if (themeMode === "light") {
//setNavigationColor("light");
UnistylesRuntime.setTheme("light");
UnistylesRuntime.navigationBar.setColor("#FFFFFF");
return setMode("light");
}
})();
}, [mode, setMode, theme]); |
Beta Was this translation helpful? Give feedback.
-
Hi @jpudysz, hope you're doing well.
I think it would be nice to integrate this: https://github.com/kadiraydinli/react-native-system-navigation-bar#setnavigationcolor so we can set the navigation bar and the status bar to desired colors based on the themes.
Right now it's a big pain to set (plus an extra dep with tons of other unneeded functions) to set the colors on androids since you have to set the colors on mount and then unset on the unmount back to the app's colors.
scenario:
Another scenario is this onboarding flow where all the screens have white background except this one:
Click me
Hope I made it clear 😅
Beta Was this translation helpful? Give feedback.
All reactions