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.

SmallDashboardItem.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // @flow
  2. import * as React from 'react';
  3. import {Badge, TouchableRipple, withTheme} from 'react-native-paper';
  4. import {Dimensions, Image, View} from 'react-native';
  5. import * as Animatable from 'react-native-animatable';
  6. import type {CustomThemeType} from '../../managers/ThemeManager';
  7. type PropsType = {
  8. image: string | null,
  9. onPress: () => void | null,
  10. badgeCount: number | null,
  11. theme: CustomThemeType,
  12. };
  13. const AnimatableBadge = Animatable.createAnimatableComponent(Badge);
  14. /**
  15. * Component used to render a small dashboard item
  16. */
  17. class SmallDashboardItem extends React.Component<PropsType> {
  18. itemSize: number;
  19. constructor(props: PropsType) {
  20. super(props);
  21. this.itemSize = Dimensions.get('window').width / 8;
  22. }
  23. shouldComponentUpdate(nextProps: PropsType): boolean {
  24. const {props} = this;
  25. return (
  26. nextProps.theme.dark !== props.theme.dark ||
  27. nextProps.badgeCount !== props.badgeCount
  28. );
  29. }
  30. render(): React.Node {
  31. const {props} = this;
  32. return (
  33. <TouchableRipple
  34. onPress={props.onPress}
  35. borderless
  36. style={{
  37. marginLeft: this.itemSize / 6,
  38. marginRight: this.itemSize / 6,
  39. }}>
  40. <View
  41. style={{
  42. width: this.itemSize,
  43. height: this.itemSize,
  44. }}>
  45. <Image
  46. source={{uri: props.image}}
  47. style={{
  48. width: '80%',
  49. height: '80%',
  50. marginLeft: 'auto',
  51. marginRight: 'auto',
  52. marginTop: 'auto',
  53. marginBottom: 'auto',
  54. }}
  55. />
  56. {props.badgeCount != null && props.badgeCount > 0 ? (
  57. <AnimatableBadge
  58. animation="zoomIn"
  59. duration={300}
  60. useNativeDriver
  61. style={{
  62. position: 'absolute',
  63. top: 0,
  64. right: 0,
  65. backgroundColor: props.theme.colors.primary,
  66. borderColor: props.theme.colors.background,
  67. borderWidth: 2,
  68. }}>
  69. {props.badgeCount}
  70. </AnimatableBadge>
  71. ) : null}
  72. </View>
  73. </TouchableRipple>
  74. );
  75. }
  76. }
  77. export default withTheme(SmallDashboardItem);