2023-07-18 21:01:31 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2019-03-12 16:23:06 +00:00
|
|
|
import { StatusBar as StatusBarRN } from 'react-native';
|
|
|
|
|
2022-03-21 19:10:11 +00:00
|
|
|
import { useTheme } from '../theme';
|
|
|
|
|
|
|
|
const supportedStyles = {
|
|
|
|
'light-content': 'light-content',
|
|
|
|
'dark-content': 'dark-content'
|
|
|
|
};
|
2019-03-12 16:23:06 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IStatusBar {
|
2022-03-21 19:10:11 +00:00
|
|
|
barStyle?: keyof typeof supportedStyles;
|
2022-01-17 16:10:39 +00:00
|
|
|
backgroundColor?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 19:10:11 +00:00
|
|
|
const StatusBar = React.memo(({ barStyle, backgroundColor }: IStatusBar) => {
|
2023-07-18 21:01:31 +00:00
|
|
|
const { theme, colors } = useTheme();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!barStyle) {
|
|
|
|
barStyle = 'light-content';
|
|
|
|
if (theme === 'light') {
|
|
|
|
barStyle = 'dark-content';
|
|
|
|
}
|
2020-06-26 20:22:56 +00:00
|
|
|
}
|
2023-07-18 21:01:31 +00:00
|
|
|
StatusBarRN.setBackgroundColor(backgroundColor ?? colors.headerBackground);
|
|
|
|
StatusBarRN.setBarStyle(barStyle, true);
|
|
|
|
}, [theme, barStyle, backgroundColor]);
|
|
|
|
|
|
|
|
return <StatusBarRN />;
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2022-03-21 19:10:11 +00:00
|
|
|
export default StatusBar;
|