Application Android et IOS pour l'amicale des élèves
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.

CustomHeader.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // @flow
  2. import * as React from "react";
  3. import {Body, Header, Input, Item, Left, Right, Title} from "native-base";
  4. import {Platform, StyleSheet, View} from "react-native";
  5. import {getStatusBarHeight} from "react-native-status-bar-height";
  6. import Touchable from 'react-native-platform-touchable';
  7. import ThemeManager from "../utils/ThemeManager";
  8. import CustomMaterialIcon from "./CustomMaterialIcon";
  9. import i18n from "i18n-js";
  10. type Props = {
  11. hasBackButton: boolean,
  12. hasSearchField: boolean,
  13. searchCallback: Function,
  14. leftButton: React.Node,
  15. rightButton: React.Node,
  16. title: string,
  17. navigation: Object,
  18. hasTabs: boolean,
  19. };
  20. /**
  21. * Custom component defining a header using native base
  22. *
  23. * @prop hasBackButton {boolean} Whether to show a back button or a burger menu. Use burger if unspecified
  24. * @prop rightMenu {React.Node} Element to place at the right of the header. Use nothing if unspecified
  25. * @prop title {string} This header title
  26. * @prop navigation {Object} The navigation object from react navigation
  27. */
  28. export default class CustomHeader extends React.Component<Props> {
  29. static defaultProps = {
  30. hasBackButton: false,
  31. hasSearchField: false,
  32. searchCallback: () => null,
  33. title: '',
  34. leftButton: <View/>,
  35. rightButton: <View/>,
  36. hasTabs: false,
  37. };
  38. getSearchBar() {
  39. return (
  40. <Item
  41. style={{
  42. width: '100%',
  43. marginBottom: 7
  44. }}>
  45. <Input placeholder={i18n.t('proximoScreen.search')}
  46. onChangeText={(text) => this.props.searchCallback(text)}/>
  47. </Item>
  48. );
  49. }
  50. render() {
  51. let button;
  52. // Does the app have a back button or a burger menu ?
  53. if (this.props.hasBackButton)
  54. button =
  55. <Touchable
  56. style={{padding: 6}}
  57. onPress={() => this.props.navigation.goBack()}>
  58. <CustomMaterialIcon
  59. color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
  60. icon="arrow-left"/>
  61. </Touchable>;
  62. else
  63. button = this.props.leftButton;
  64. return (
  65. <Header style={styles.header}
  66. hasTabs={this.props.hasTabs}>
  67. <Left>
  68. {button}
  69. </Left>
  70. <Body>
  71. {this.props.hasSearchField ?
  72. this.getSearchBar() :
  73. <Title>{this.props.title}</Title>}
  74. </Body>
  75. <Right>
  76. {this.props.rightButton}
  77. {this.props.hasBackButton ? <View/> :
  78. <Touchable
  79. style={{padding: 6}}
  80. onPress={() => this.props.navigation.navigate('SettingsScreen')}>
  81. <CustomMaterialIcon
  82. color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
  83. icon="settings"/>
  84. </Touchable>}
  85. </Right>
  86. </Header>);
  87. }
  88. };
  89. // Fix header in status bar on Android
  90. const styles = StyleSheet.create({
  91. header: {
  92. paddingTop: getStatusBarHeight(),
  93. height: 54 + getStatusBarHeight(),
  94. },
  95. });