You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiStatusBar.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // @flow
  2. import React, { useCallback } from 'react';
  3. import { StatusBar } from 'react-native';
  4. import { ColorSchemeRegistry } from '../../color-scheme';
  5. import { connect } from '../../redux';
  6. import { isDarkColor } from '../../styles';
  7. // Register style
  8. import '../../react/components/native/headerstyles';
  9. /**
  10. * Constants for the (currently) supported statusbar colors.
  11. */
  12. const STATUSBAR_DARK = 'dark-content';
  13. const STATUSBAR_LIGHT = 'light-content';
  14. type Props = {
  15. /**
  16. * The color schemed style of the component.
  17. */
  18. _styles: Object
  19. }
  20. const JitsiStatusBar = ({ _styles }: Props) => {
  21. const getStatusBarContentColor = useCallback(() => {
  22. const { statusBarContent } = _styles;
  23. if (statusBarContent) {
  24. // We have the possibility to define the statusbar color in the
  25. // color scheme feature, but since mobile devices (at the moment)
  26. // only support two colors (light and dark) we need to normalize
  27. // the value.
  28. if (isDarkColor(statusBarContent)) {
  29. return STATUSBAR_DARK;
  30. }
  31. return STATUSBAR_LIGHT;
  32. }
  33. // The statusbar color is not defined, so we need to base our choice
  34. // on the header colors
  35. const { statusBar, screenHeader } = _styles;
  36. if (isDarkColor(statusBar || screenHeader.backgroundColor)) {
  37. return STATUSBAR_LIGHT;
  38. }
  39. return STATUSBAR_DARK;
  40. }, [ _styles ]);
  41. return (
  42. <StatusBar
  43. backgroundColor = { _styles.statusBar }
  44. barStyle = { getStatusBarContentColor() }
  45. translucent = { false } />
  46. );
  47. };
  48. /**
  49. * Maps part of the Redux state to the props of the component.
  50. *
  51. * @param {Object} state - The Redux state.
  52. * @returns {{
  53. * _styles: Object
  54. * }}
  55. */
  56. function _mapStateToProps(state) {
  57. return {
  58. _styles: ColorSchemeRegistry.get(state, 'Header')
  59. };
  60. }
  61. export default connect(_mapStateToProps)(JitsiStatusBar);