Fix android browsers background-color issues by setting theme-color meta (#1063)
This commit is contained in:
10
index.html
10
index.html
@@ -51,6 +51,16 @@
|
|||||||
|
|
||||||
if (backgroundColor) {
|
if (backgroundColor) {
|
||||||
document.documentElement.style.backgroundColor = backgroundColor;
|
document.documentElement.style.backgroundColor = backgroundColor;
|
||||||
|
// android chromium-based browser/pwa background color (e.g. top status bar and navigation bar) will change dynamically based on meta theme-color
|
||||||
|
let themeColorMeta = document.querySelector('meta[name="theme-color"]');
|
||||||
|
if (!themeColorMeta) {
|
||||||
|
themeColorMeta = document.createElement('meta');
|
||||||
|
themeColorMeta.setAttribute('name', 'theme-color');
|
||||||
|
document.head.appendChild(themeColorMeta);
|
||||||
|
}
|
||||||
|
if (themeColorMeta.getAttribute('content') !== backgroundColor) {
|
||||||
|
themeColorMeta.setAttribute('content', backgroundColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
@@ -131,8 +131,19 @@ export const AppThemeContextProvider = ({ children }: { children: ReactNode }) =
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// The set background color is not necessary anymore, since the theme has been loaded
|
// The set background color is not necessary anymore, since the theme has been loaded
|
||||||
document.documentElement.style.backgroundColor = '';
|
document.documentElement.style.backgroundColor = '';
|
||||||
|
const themeBackgroundColor = theme.palette.background.default;
|
||||||
|
|
||||||
AppStorage.local.setItem('theme_background', theme.palette.background.default);
|
AppStorage.local.setItem('theme_background', themeBackgroundColor);
|
||||||
|
// android chromium-based browser/pwa background color (e.g. top status bar and navigation bar) will change dynamically based on meta theme-color
|
||||||
|
let themeColorMeta = document.querySelector('meta[name="theme-color"]');
|
||||||
|
if (!themeColorMeta) {
|
||||||
|
themeColorMeta = document.createElement('meta');
|
||||||
|
themeColorMeta.setAttribute('name', 'theme-color');
|
||||||
|
document.head.appendChild(themeColorMeta);
|
||||||
|
}
|
||||||
|
if (themeColorMeta.getAttribute('content') !== themeBackgroundColor) {
|
||||||
|
themeColorMeta.setAttribute('content', themeBackgroundColor);
|
||||||
|
}
|
||||||
}, [theme.palette.background.default]);
|
}, [theme.palette.background.default]);
|
||||||
|
|
||||||
if (directionRef.current !== currentDirection) {
|
if (directionRef.current !== currentDirection) {
|
||||||
|
|||||||
Reference in New Issue
Block a user