-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathindex.android.js
69 lines (63 loc) · 2.81 KB
/
index.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, {memo, useCallback, useContext} from 'react';
import {StyleSheet, View} from 'react-native';
import {Gesture, GestureDetector} from 'react-native-gesture-handler';
import Animated, {useSharedValue} from 'react-native-reanimated';
import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
import useThemeStyles from '@hooks/useThemeStyles';
import BaseAttachmentViewPdf from './BaseAttachmentViewPdf';
import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes';
function AttachmentViewPdf(props) {
const styles = useThemeStyles();
const {onScaleChanged, ...restProps} = props;
const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext);
const scaleRef = useSharedValue(1);
const offsetX = useSharedValue(0);
const offsetY = useSharedValue(0);
const Pan = Gesture.Pan()
.manualActivation(true)
.onTouchesMove((evt) => {
if (offsetX.value !== 0 && offsetY.value !== 0) {
// if the value of X is greater than Y and the pdf is not zoomed in,
// enable the pager scroll so that the user
// can swipe to the next attachment otherwise disable it.
if (Math.abs(evt.allTouches[0].absoluteX - offsetX.value) > Math.abs(evt.allTouches[0].absoluteY - offsetY.value) && scaleRef.value === 1) {
attachmentCarouselPagerContext.shouldPagerScroll.value = true;
} else {
attachmentCarouselPagerContext.shouldPagerScroll.value = false;
}
}
offsetX.value = evt.allTouches[0].absoluteX;
offsetY.value = evt.allTouches[0].absoluteY;
});
const updateScale = useCallback(
(scale) => {
scaleRef.value = scale;
},
[scaleRef],
);
return (
<View
collapsable={false}
style={styles.flex1}
>
<GestureDetector gesture={Pan}>
<Animated.View
collapsable={false}
style={[StyleSheet.absoluteFill, styles.justifyContentCenter, styles.alignItemsCenter]}
>
<BaseAttachmentViewPdf
// eslint-disable-next-line react/jsx-props-no-spreading
{...restProps}
onScaleChanged={(scale) => {
updateScale(scale);
onScaleChanged();
}}
/>
</Animated.View>
</GestureDetector>
</View>
);
}
AttachmentViewPdf.propTypes = attachmentViewPdfPropTypes;
AttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps;
export default memo(AttachmentViewPdf);