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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // @flow
  2. import * as React from "react";
  3. import {Body, Header, Input, Item, Left, Right, Title, Form} 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. shouldFocusSearchBar: boolean,
  15. leftButton: React.Node,
  16. rightButton: React.Node,
  17. title: string,
  18. navigation: Object,
  19. hasTabs: boolean,
  20. };
  21. /**
  22. * Custom component defining a header using native base
  23. *
  24. * @prop hasBackButton {boolean} Whether to show a back button or a burger menu. Use burger if unspecified
  25. * @prop rightMenu {React.Node} Element to place at the right of the header. Use nothing if unspecified
  26. * @prop title {string} This header title
  27. * @prop navigation {Object} The navigation object from react navigation
  28. */
  29. export default class CustomHeader extends React.Component<Props> {
  30. static defaultProps = {
  31. hasBackButton: false,
  32. hasSearchField: false,
  33. searchCallback: () => null,
  34. shouldFocusSearchBar: false,
  35. title: '',
  36. leftButton: <View/>,
  37. rightButton: <View/>,
  38. hasTabs: false,
  39. };
  40. componentDidMount() {
  41. if (this.refs.searchInput !== undefined && this.refs.searchInput._root !== undefined && this.props.shouldFocusSearchBar) {
  42. // does not work if called to early for some reason...
  43. setTimeout(() => this.refs.searchInput._root.focus(), 500);
  44. }
  45. }
  46. getSearchBar() {
  47. return (
  48. <Form>
  49. <Item
  50. style={{
  51. width: '100%',
  52. marginBottom: 7
  53. }}>
  54. <CustomMaterialIcon
  55. icon={'magnify'}
  56. color={ThemeManager.getCurrentThemeVariables().toolbarBtnColor}/>
  57. <Input
  58. ref="searchInput"
  59. placeholder={i18n.t('proximoScreen.search')}
  60. placeholderTextColor={ThemeManager.getCurrentThemeVariables().toolbarPlaceholderColor}
  61. onChangeText={(text) => this.props.searchCallback(text)}/>
  62. </Item>
  63. </Form>
  64. );
  65. }
  66. render() {
  67. let button;
  68. // Does the app have a back button or a burger menu ?
  69. if (this.props.hasBackButton)
  70. button =
  71. <Touchable
  72. style={{padding: 6}}
  73. onPress={() => this.props.navigation.goBack()}>
  74. <CustomMaterialIcon
  75. color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
  76. icon="arrow-left"/>
  77. </Touchable>;
  78. else
  79. button = this.props.leftButton;
  80. return (
  81. <Header style={styles.header}
  82. hasTabs={this.props.hasTabs}>
  83. <Left style={{flex: 0}}>
  84. {button}
  85. </Left>
  86. <Body>
  87. {this.props.hasSearchField ?
  88. this.getSearchBar() :
  89. <Title>{this.props.title}</Title>}
  90. </Body>
  91. <Right style={{flex: this.props.hasSearchField ? 0 : 1}}>
  92. {this.props.rightButton}
  93. {this.props.hasBackButton ? <View/> :
  94. <Touchable
  95. style={{padding: 6}}
  96. onPress={() => this.props.navigation.navigate('SettingsScreen')}>
  97. <CustomMaterialIcon
  98. color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
  99. icon="settings"/>
  100. </Touchable>}
  101. </Right>
  102. </Header>);
  103. }
  104. };
  105. // Fix header in status bar on Android
  106. const styles = StyleSheet.create({
  107. header: {
  108. paddingTop: getStatusBarHeight(),
  109. height: 54 + getStatusBarHeight(),
  110. },
  111. });