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.

ImageGalleryScreen.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // @flow
  2. import * as React from 'react';
  3. import {IconButton, Text} from 'react-native-paper';
  4. import ImageViewer from 'react-native-image-zoom-viewer';
  5. import {StackNavigationProp} from '@react-navigation/stack';
  6. import * as Animatable from 'react-native-animatable';
  7. type PropsType = {
  8. navigation: StackNavigationProp,
  9. route: {params: {images: Array<{url: string}>}},
  10. };
  11. class ImageGalleryScreen extends React.Component<PropsType> {
  12. images: Array<{url: string}>;
  13. closeButtonRef: {current: null | Animatable.View};
  14. indicatorRef: {current: null | Animatable.View};
  15. controlsShown: boolean;
  16. constructor(props: PropsType) {
  17. super(props);
  18. this.closeButtonRef = React.createRef();
  19. this.indicatorRef = React.createRef();
  20. this.controlsShown = true;
  21. if (props.route.params != null) this.images = props.route.params.images;
  22. }
  23. goBack = () => {
  24. const {navigation} = this.props;
  25. navigation.goBack();
  26. };
  27. getRenderHeader = (): React.Node => {
  28. return (
  29. <Animatable.View
  30. ref={this.closeButtonRef}
  31. useNativeDriver
  32. style={{
  33. position: 'absolute',
  34. top: 10,
  35. left: 10,
  36. zIndex: 1000,
  37. }}>
  38. <IconButton
  39. onPress={this.goBack}
  40. icon="close"
  41. size={30}
  42. style={{backgroundColor: 'rgba(0,0,0,0.6)'}}
  43. />
  44. </Animatable.View>
  45. );
  46. };
  47. getRenderIndicator = (
  48. currentIndex?: number,
  49. allSize?: number,
  50. ): React.Node => {
  51. if (currentIndex != null && allSize != null && allSize !== 1)
  52. return (
  53. <Animatable.View
  54. ref={this.indicatorRef}
  55. useNativeDriver
  56. style={{
  57. width: '100%',
  58. height: 50,
  59. position: 'absolute',
  60. }}>
  61. <Text
  62. style={{
  63. marginLeft: 'auto',
  64. marginRight: 'auto',
  65. marginTop: 'auto',
  66. marginBottom: 'auto',
  67. fontSize: 15,
  68. backgroundColor: 'rgba(0,0,0,0.6)',
  69. padding: 10,
  70. borderRadius: 20,
  71. }}>
  72. {currentIndex}/{allSize}
  73. </Text>
  74. </Animatable.View>
  75. );
  76. return null;
  77. };
  78. onImageClick = () => {
  79. if (this.controlsShown) this.hideControls();
  80. else this.showControls();
  81. this.controlsShown = !this.controlsShown;
  82. };
  83. hideControls() {
  84. if (this.closeButtonRef.current != null)
  85. this.closeButtonRef.current.fadeOutUp(200);
  86. if (this.indicatorRef.current != null)
  87. this.indicatorRef.current.fadeOutUp(300);
  88. }
  89. showControls() {
  90. if (this.closeButtonRef.current != null)
  91. this.closeButtonRef.current.fadeInDown(300);
  92. if (this.indicatorRef.current != null)
  93. this.indicatorRef.current.fadeInDown(400);
  94. }
  95. render(): React.Node {
  96. return (
  97. <ImageViewer
  98. useNativeDriver
  99. imageUrls={this.images}
  100. enableSwipeDown
  101. onSwipeDown={this.goBack}
  102. renderHeader={this.getRenderHeader}
  103. renderIndicator={this.getRenderIndicator}
  104. pageAnimateTime={100}
  105. onClick={this.onImageClick}
  106. doubleClickInterval={250}
  107. />
  108. );
  109. }
  110. }
  111. export default ImageGalleryScreen;