fix: Android status bar theme on the first open isn't working properly (#5132)

* fix: status bar color and text color update properly

* change how to set the status bar

* add colors
This commit is contained in:
Reinaldo Neto 2023-07-18 18:01:31 -03:00 committed by GitHub
parent 192d5db179
commit 456344029c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 9 deletions

View File

@ -1,7 +1,6 @@
import React from 'react';
import React, { useEffect } from 'react';
import { StatusBar as StatusBarRN } from 'react-native';
import { themes } from '../lib/constants';
import { useTheme } from '../theme';
const supportedStyles = {
@ -15,14 +14,20 @@ interface IStatusBar {
}
const StatusBar = React.memo(({ barStyle, backgroundColor }: IStatusBar) => {
const { theme } = useTheme();
if (!barStyle) {
barStyle = 'light-content';
if (theme === 'light') {
barStyle = 'dark-content';
const { theme, colors } = useTheme();
useEffect(() => {
if (!barStyle) {
barStyle = 'light-content';
if (theme === 'light') {
barStyle = 'dark-content';
}
}
}
return <StatusBarRN backgroundColor={backgroundColor ?? themes[theme].headerBackground} barStyle={barStyle} animated />;
StatusBarRN.setBackgroundColor(backgroundColor ?? colors.headerBackground);
StatusBarRN.setBarStyle(barStyle, true);
}, [theme, barStyle, backgroundColor]);
return <StatusBarRN />;
});
export default StatusBar;