Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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.

ErrorView.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import * as React from 'react';
  20. import { Button, Subheading, useTheme } from 'react-native-paper';
  21. import { StyleSheet, View, ViewStyle } from 'react-native';
  22. import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
  23. import * as Animatable from 'react-native-animatable';
  24. import {
  25. API_REQUEST_CODES,
  26. getErrorMessage,
  27. REQUEST_STATUS,
  28. } from '../../utils/Requests';
  29. type Props = {
  30. status?: REQUEST_STATUS;
  31. code?: API_REQUEST_CODES;
  32. icon?: string;
  33. message?: string;
  34. loading?: boolean;
  35. button?: {
  36. text: string;
  37. icon: string;
  38. onPress: () => void;
  39. };
  40. style?: ViewStyle;
  41. };
  42. const styles = StyleSheet.create({
  43. outer: {
  44. flex: 1,
  45. },
  46. inner: {
  47. marginTop: 'auto',
  48. marginBottom: 'auto',
  49. },
  50. iconContainer: {
  51. marginLeft: 'auto',
  52. marginRight: 'auto',
  53. marginBottom: 20,
  54. },
  55. subheading: {
  56. textAlign: 'center',
  57. paddingHorizontal: 20,
  58. },
  59. button: {
  60. marginTop: 10,
  61. marginLeft: 'auto',
  62. marginRight: 'auto',
  63. },
  64. });
  65. function ErrorView(props: Props) {
  66. const theme = useTheme();
  67. const fullMessage = getErrorMessage(props, props.message, props.icon);
  68. const { button } = props;
  69. return (
  70. <View style={{ ...styles.outer, ...props.style }}>
  71. <Animatable.View
  72. style={{
  73. ...styles.outer,
  74. backgroundColor: theme.colors.background,
  75. }}
  76. animation="zoomIn"
  77. duration={200}
  78. useNativeDriver
  79. >
  80. <View style={styles.inner}>
  81. <View style={styles.iconContainer}>
  82. <MaterialCommunityIcons
  83. name={fullMessage.icon}
  84. size={150}
  85. color={theme.colors.disabled}
  86. />
  87. </View>
  88. <Subheading
  89. style={{
  90. ...styles.subheading,
  91. color: theme.colors.disabled,
  92. }}
  93. >
  94. {fullMessage.message}
  95. </Subheading>
  96. {button ? (
  97. <Button
  98. mode={'contained'}
  99. icon={button.icon}
  100. onPress={button.onPress}
  101. style={styles.button}
  102. >
  103. {button.text}
  104. </Button>
  105. ) : null}
  106. </View>
  107. </Animatable.View>
  108. </View>
  109. );
  110. }
  111. export default ErrorView;