MyStatusBar.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * 自定义状态栏(Android)
  3. * @邠心vbe on 2023/02/15
  4. */
  5. import React, { Component } from 'react';
  6. import { StatusBar } from 'react-native';
  7. let statusBar;
  8. export default class MyStatusBar extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. statusTheme: themeStatusBar,
  13. statusColor: colorPrimaryDark
  14. };
  15. statusBar = this;
  16. }
  17. static DARK_STYLE = "dark-content";
  18. static LIGHT_STYLE = "light-content";
  19. /**
  20. * 设置状态栏颜色
  21. * @param {String} color 颜色值
  22. */
  23. static setStatusBarColor(color) {
  24. statusBar.setStatusBarColor(color);
  25. }
  26. /**
  27. * 设置状态栏主题(字体图标颜色)
  28. * @param {String} theme 主题:MyStatusBar.DARK_STYLE, MyStatusBar.LIGHT_STYLE
  29. */
  30. static setStatusBarTheme(theme) {
  31. statusBar.setStatusBarTheme(theme);
  32. }
  33. /**
  34. * 设置状态栏主题和颜色
  35. * @param {*} theme 主题:MyStatusBar.DARK_STYLE, MyStatusBar.LIGHT_STYLE
  36. * @param {*} color 颜色
  37. */
  38. static setStatusBarThemes(theme, color) {
  39. statusBar.setStatusBarThemes(theme, color);
  40. }
  41. setStatusBarColor(color) {
  42. this.setState({
  43. statusColor: color
  44. })
  45. }
  46. setStatusBarTheme(theme) {
  47. this.setState({
  48. statusTheme: theme
  49. })
  50. }
  51. setStatusBarThemes(theme, color) {
  52. this.setState({
  53. statusColor: color,
  54. statusTheme: theme
  55. })
  56. }
  57. render() {
  58. return (
  59. <StatusBar barStyle={this.state.statusTheme} backgroundColor={this.state.statusColor}/>
  60. );
  61. }
  62. }