-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30050 from HezekielT/fix--Android-pdf-scrolling-i…
…ssue Fix: android pdf scrolling issue
- Loading branch information
Showing
3 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
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 styles from '@styles/styles'; | ||
import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; | ||
import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; | ||
|
||
function AttachmentViewPdf(props) { | ||
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); |
17 changes: 17 additions & 0 deletions
17
src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {memo} from 'react'; | ||
import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; | ||
import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; | ||
|
||
function AttachmentViewPdf(props) { | ||
return ( | ||
<BaseAttachmentViewPdf | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
AttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; | ||
AttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; | ||
|
||
export default memo(AttachmentViewPdf); |