Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // @flow
  2. import React, { Component, type Node } from 'react';
  3. import { Platform, SafeAreaView, StatusBar, View } from 'react-native';
  4. import styles, { HEADER_PADDING, STATUSBAR_COLOR } from './styles';
  5. /**
  6. * Compatibility header padding size for iOS 10 (and older) devices.
  7. */
  8. const IOS10_PADDING = 20;
  9. /**
  10. * The type of the React {@code Component} props of {@link Header}
  11. */
  12. type Props = {
  13. /**
  14. * Children component(s).
  15. */
  16. children: Node,
  17. /**
  18. * The component's external style
  19. */
  20. style: Object
  21. }
  22. /**
  23. * A generic screen header component.
  24. */
  25. export default class Header extends Component<Props> {
  26. /**
  27. * The style of button-like React {@code Component}s rendered in
  28. * {@code Header}.
  29. *
  30. * @returns {Object}
  31. */
  32. static get buttonStyle(): Object {
  33. return styles.headerButtonIcon;
  34. }
  35. /**
  36. * The style of a React {@code Component} rendering a {@code Header} as its
  37. * child.
  38. *
  39. * @returns {Object}
  40. */
  41. static get pageStyle(): Object {
  42. return styles.page;
  43. }
  44. /**
  45. * The style of text rendered in {@code Header}.
  46. *
  47. * @returns {Object}
  48. */
  49. static get textStyle(): Object {
  50. return styles.headerText;
  51. }
  52. /**
  53. * Initializes a new {@code Header} instance.
  54. *
  55. * @inheritdoc
  56. */
  57. constructor(props: Props) {
  58. super(props);
  59. this._getIOS10CompatiblePadding
  60. = this._getIOS10CompatiblePadding.bind(this);
  61. }
  62. /**
  63. * Implements React's {@link Component#render()}.
  64. *
  65. * @inheritdoc
  66. */
  67. render() {
  68. return (
  69. <View
  70. style = { [
  71. styles.headerOverlay,
  72. this._getIOS10CompatiblePadding()
  73. ] } >
  74. <StatusBar
  75. backgroundColor = { STATUSBAR_COLOR }
  76. barStyle = 'light-content'
  77. translucent = { false } />
  78. <SafeAreaView>
  79. <View
  80. style = { [
  81. styles.screenHeader,
  82. this.props.style
  83. ] }>
  84. {
  85. this.props.children
  86. }
  87. </View>
  88. </SafeAreaView>
  89. </View>
  90. );
  91. }
  92. _getIOS10CompatiblePadding: () => Object;
  93. /**
  94. * Adds a padding for iOS 10 (and older) devices to avoid clipping with the
  95. * status bar.
  96. * Note: This is a workaround for iOS 10 (and older) devices only to fix
  97. * usability, but it doesn't take orientation into account, so unnecessary
  98. * padding is rendered in some cases.
  99. *
  100. * @private
  101. * @returns {Object}
  102. */
  103. _getIOS10CompatiblePadding() {
  104. if (Platform.OS === 'ios') {
  105. const majorVersionIOS = parseInt(Platform.Version, 10);
  106. if (majorVersionIOS <= 10) {
  107. return {
  108. paddingTop: HEADER_PADDING + IOS10_PADDING
  109. };
  110. }
  111. }
  112. return null;
  113. }
  114. }