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.

BaseContainer.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // @flow
  2. import * as React from 'react';
  3. import {Container, Right} from "native-base";
  4. import CustomHeader from "./CustomHeader";
  5. import CustomSideMenu from "./CustomSideMenu";
  6. import CustomMaterialIcon from "./CustomMaterialIcon";
  7. import {Platform, View} from "react-native";
  8. import ThemeManager from "../utils/ThemeManager";
  9. import Touchable from "react-native-platform-touchable";
  10. type Props = {
  11. navigation: Object,
  12. headerTitle: string,
  13. headerRightButton: React.Node,
  14. children: React.Node,
  15. hasTabs: boolean,
  16. hasBackButton: boolean
  17. }
  18. type State = {
  19. isOpen: boolean
  20. }
  21. export default class BaseContainer extends React.Component<Props, State> {
  22. willBlurSubscription: function;
  23. static defaultProps = {
  24. headerRightButton: <View/>,
  25. hasTabs: false,
  26. hasBackButton: false,
  27. };
  28. state = {
  29. isOpen: false,
  30. };
  31. toggle() {
  32. this.setState({
  33. isOpen: !this.state.isOpen,
  34. });
  35. }
  36. updateMenuState(isOpen: boolean) {
  37. this.setState({isOpen});
  38. }
  39. /**
  40. * Register for blur event to close side menu on screen change
  41. */
  42. componentDidMount() {
  43. this.willBlurSubscription = this.props.navigation.addListener(
  44. 'willBlur',
  45. payload => {
  46. this.setState({isOpen: false});
  47. }
  48. );
  49. }
  50. /**
  51. * Unregister from event when un-mounting components
  52. */
  53. componentWillUnmount() {
  54. if (this.willBlurSubscription !== undefined)
  55. this.willBlurSubscription.remove();
  56. }
  57. render() {
  58. return (
  59. <View style={{
  60. backgroundColor: ThemeManager.getCurrentThemeVariables().sideMenuBgColor,
  61. width: '100%',
  62. height: '100%'
  63. }}>
  64. <CustomSideMenu
  65. navigation={this.props.navigation} isOpen={this.state.isOpen}
  66. onChange={(isOpen) => this.updateMenuState(isOpen)}>
  67. <Container>
  68. <CustomHeader
  69. navigation={this.props.navigation} title={this.props.headerTitle}
  70. leftButton={
  71. <Touchable
  72. style={{padding: 6}}
  73. onPress={() => this.toggle()}>
  74. <CustomMaterialIcon
  75. color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
  76. icon="menu"/>
  77. </Touchable>
  78. }
  79. rightButton={this.props.headerRightButton}
  80. hasTabs={this.props.hasTabs}
  81. hasBackButton={this.props.hasBackButton}/>
  82. {this.props.children}
  83. </Container>
  84. </CustomSideMenu>
  85. </View>
  86. );
  87. }
  88. }