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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // @flow
  2. import * as React from "react";
  3. import {Body, Header, 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. type Props = {
  10. hasBackButton: boolean,
  11. leftButton: React.Node,
  12. rightButton: React.Node,
  13. title: string,
  14. navigation: Object,
  15. hasTabs: boolean,
  16. };
  17. /**
  18. * Custom component defining a header using native base
  19. *
  20. * @prop hasBackButton {boolean} Whether to show a back button or a burger menu. Use burger if unspecified
  21. * @prop rightMenu {React.Node} Element to place at the right of the header. Use nothing if unspecified
  22. * @prop title {string} This header title
  23. * @prop navigation {Object} The navigation object from react navigation
  24. */
  25. export default class CustomHeader extends React.Component<Props> {
  26. static defaultProps = {
  27. hasBackButton: false,
  28. leftButton: <View/>,
  29. rightButton: <View/>,
  30. hasTabs: false,
  31. };
  32. render() {
  33. let button;
  34. // Does the app have a back button or a burger menu ?
  35. if (this.props.hasBackButton)
  36. button =
  37. <Touchable
  38. style={{padding: 6}}
  39. onPress={() => this.props.navigation.goBack()}>
  40. <CustomMaterialIcon
  41. color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
  42. icon="arrow-left"/>
  43. </Touchable>;
  44. else
  45. button = this.props.leftButton;
  46. return (
  47. <Header style={styles.header}
  48. hasTabs={this.props.hasTabs}>
  49. <Left>
  50. {button}
  51. </Left>
  52. <Body>
  53. <Title>{this.props.title}</Title>
  54. </Body>
  55. <Right>
  56. {this.props.rightButton}
  57. {this.props.hasBackButton ? <View/> :
  58. <Touchable
  59. style={{padding: 6}}
  60. onPress={() => this.props.navigation.navigate('SettingsScreen')}>
  61. <CustomMaterialIcon
  62. color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
  63. icon="settings"/>
  64. </Touchable>}
  65. </Right>
  66. </Header>);
  67. }
  68. };
  69. // Fix header in status bar on Android
  70. const styles = StyleSheet.create({
  71. header: {
  72. paddingTop: getStatusBarHeight(),
  73. height: 54 + getStatusBarHeight(),
  74. },
  75. });