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.

SmallDashboardItem.js 2.7KB

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