From d7fe00b46a3331cf2abbc981a893423bea0b5852 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Tue, 24 Oct 2023 09:07:24 +0300 Subject: [PATCH 01/14] fix: resolve conflict --- ...dex.native.js => BaseAttachmentViewPdf.js} | 26 ++++++-- .../AttachmentViewPdf/index.android.js | 64 +++++++++++++++++++ .../AttachmentViewPdf/index.ios.js | 17 +++++ 3 files changed, 101 insertions(+), 6 deletions(-) rename src/components/Attachments/AttachmentView/AttachmentViewPdf/{index.native.js => BaseAttachmentViewPdf.js} (69%) create mode 100644 src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js create mode 100644 src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.native.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js similarity index 69% rename from src/components/Attachments/AttachmentView/AttachmentViewPdf/index.native.js rename to src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index 9ab0b45f8c8f..81b52ebb142f 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.native.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -3,7 +3,19 @@ import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCa import PDFView from '@components/PDFView'; import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; -function AttachmentViewPdf({file, encryptedSourceUrl, isFocused, isUsedInCarousel, onPress, onScaleChanged: onScaleChangedProp, onToggleKeyboard, onLoadComplete, errorLabelStyles, style}) { +const propTypes = { + /** Updates the scale value of the pdf */ + updateScaleRef: PropTypes.func, + + ...attachmentViewPdfPropTypes, +}; + +const defaultProps = { + updateScaleRef: () => {}, + ...attachmentViewPdfDefaultProps, +}; + +function BaseAttachmentViewPdf({file, encryptedSourceUrl, isFocused, isUsedInCarousel, onPress, onScaleChanged: onScaleChangedProp, onToggleKeyboard, onLoadComplete, errorLabelStyles, style, updateScaleRef}) { const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); useEffect(() => { @@ -16,7 +28,8 @@ function AttachmentViewPdf({file, encryptedSourceUrl, isFocused, isUsedInCarouse const onScaleChanged = useCallback( (scale) => { - onScaleChangedProp(); + updateScaleRef(scale); + onScaleChangedProp(scale); // When a pdf is shown in a carousel, we want to disable the pager scroll when the pdf is zoomed in if (isUsedInCarousel) { @@ -31,7 +44,7 @@ function AttachmentViewPdf({file, encryptedSourceUrl, isFocused, isUsedInCarouse attachmentCarouselPagerContext.shouldPagerScroll.value = shouldPagerScroll; } }, - [attachmentCarouselPagerContext, isUsedInCarousel, onScaleChangedProp], + [attachmentCarouselPagerContext, isUsedInCarousel, onScaleChangedProp, updateScaleRef], ); return ( @@ -49,7 +62,8 @@ function AttachmentViewPdf({file, encryptedSourceUrl, isFocused, isUsedInCarouse ); } -AttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; -AttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; +BaseAttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; +BaseAttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; +BaseAttachmentViewPdf.displayName = 'BaseAttachmentViewPdf'; -export default memo(AttachmentViewPdf); +export default memo(BaseAttachmentViewPdf); diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js new file mode 100644 index 000000000000..f4f9dbddc37d --- /dev/null +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -0,0 +1,64 @@ +import React, {memo, useCallback, useContext} from 'react'; +import {Gesture, GestureDetector} from 'react-native-gesture-handler'; +import Animated, {useSharedValue} from 'react-native-reanimated'; +import {View, StyleSheet} from 'react-native'; +import styles from '../../../../styles/styles'; +import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propTypes'; +import AttachmentCarouselPagerContext from '../../AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; +import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; + +function AttachmentViewPdf(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 updateScaleRef = useCallback( + (scale) => { + scaleRef.value = scale; + }, + [scaleRef], + ); + + return ( + + + + + + + + ); +} + +AttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; +AttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; + +export default memo(AttachmentViewPdf); diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js new file mode 100644 index 000000000000..94440e1d17cb --- /dev/null +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js @@ -0,0 +1,17 @@ +import React, {memo} from 'react'; +import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; +import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propTypes'; + +function AttachmentViewPdf(props) { + return ( + + ); +} + +AttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; +AttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; + +export default memo(AttachmentViewPdf); From 56b896933f3ab5863e0d0db449e84d4fb24f647a Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Tue, 24 Oct 2023 09:10:33 +0300 Subject: [PATCH 02/14] remove unnecessary change --- .../AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index 81b52ebb142f..479251a7d35a 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -29,7 +29,7 @@ function BaseAttachmentViewPdf({file, encryptedSourceUrl, isFocused, isUsedInCar const onScaleChanged = useCallback( (scale) => { updateScaleRef(scale); - onScaleChangedProp(scale); + onScaleChangedProp(); // When a pdf is shown in a carousel, we want to disable the pager scroll when the pdf is zoomed in if (isUsedInCarousel) { From 864314d739c0138a66b18f4d039dca414435f6cf Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Tue, 24 Oct 2023 09:28:39 +0300 Subject: [PATCH 03/14] fix lint issue --- .../AttachmentViewPdf/BaseAttachmentViewPdf.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index 479251a7d35a..b19d8496f0c6 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -15,7 +15,19 @@ const defaultProps = { ...attachmentViewPdfDefaultProps, }; -function BaseAttachmentViewPdf({file, encryptedSourceUrl, isFocused, isUsedInCarousel, onPress, onScaleChanged: onScaleChangedProp, onToggleKeyboard, onLoadComplete, errorLabelStyles, style, updateScaleRef}) { +function BaseAttachmentViewPdf({ + file, + encryptedSourceUrl, + isFocused, + isUsedInCarousel, + onPress, + onScaleChanged: onScaleChangedProp, + onToggleKeyboard, + onLoadComplete, + errorLabelStyles, + style, + updateScaleRef, +}) { const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); useEffect(() => { From 58b854123c94644c9fa3236ec30153170bb451e3 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Tue, 24 Oct 2023 09:34:15 +0300 Subject: [PATCH 04/14] fix unused variables --- .../AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index b19d8496f0c6..f320a72e5eac 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -74,8 +74,8 @@ function BaseAttachmentViewPdf({ ); } -BaseAttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; -BaseAttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; +BaseAttachmentViewPdf.propTypes = propTypes; +BaseAttachmentViewPdf.defaultProps = defaultProps; BaseAttachmentViewPdf.displayName = 'BaseAttachmentViewPdf'; export default memo(BaseAttachmentViewPdf); From 0e85cc58b5564a0ba897b68935158348a604349f Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Wed, 25 Oct 2023 18:12:01 +0300 Subject: [PATCH 05/14] Rename updateScaleRef --- .../AttachmentViewPdf/BaseAttachmentViewPdf.js | 10 +++++----- .../AttachmentView/AttachmentViewPdf/index.android.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index f320a72e5eac..c1d75bd789e5 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -5,13 +5,13 @@ import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propT const propTypes = { /** Updates the scale value of the pdf */ - updateScaleRef: PropTypes.func, + updateScale: PropTypes.func, ...attachmentViewPdfPropTypes, }; const defaultProps = { - updateScaleRef: () => {}, + updateScale: () => {}, ...attachmentViewPdfDefaultProps, }; @@ -26,7 +26,7 @@ function BaseAttachmentViewPdf({ onLoadComplete, errorLabelStyles, style, - updateScaleRef, + updateScale, }) { const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); @@ -40,7 +40,7 @@ function BaseAttachmentViewPdf({ const onScaleChanged = useCallback( (scale) => { - updateScaleRef(scale); + updateScale(scale); onScaleChangedProp(); // When a pdf is shown in a carousel, we want to disable the pager scroll when the pdf is zoomed in @@ -56,7 +56,7 @@ function BaseAttachmentViewPdf({ attachmentCarouselPagerContext.shouldPagerScroll.value = shouldPagerScroll; } }, - [attachmentCarouselPagerContext, isUsedInCarousel, onScaleChangedProp, updateScaleRef], + [attachmentCarouselPagerContext, isUsedInCarousel, onScaleChangedProp, updateScale], ); return ( diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index f4f9dbddc37d..410badb229e8 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -30,7 +30,7 @@ function AttachmentViewPdf(props) { offsetY.value = evt.allTouches[0].absoluteY; }); - const updateScaleRef = useCallback( + const updateScale = useCallback( (scale) => { scaleRef.value = scale; }, @@ -50,7 +50,7 @@ function AttachmentViewPdf(props) { From 73d1d0dad18bc9aef03cd022ab51b005219af800 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 06:29:29 +0300 Subject: [PATCH 06/14] fix: resolve conflict --- .../AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index c1d75bd789e5..e0f3e9ab8454 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -1,4 +1,5 @@ import React, {memo, useCallback, useContext, useEffect} from 'react'; +import PropTypes from 'prop-types'; import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; import PDFView from '@components/PDFView'; import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; From d0ca77b898a4fd4b8a82ccb8e73e1112cf382fec Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 07:01:18 +0300 Subject: [PATCH 07/14] fix: resolve conflict --- .../AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js | 1 + .../AttachmentView/AttachmentViewPdf/index.android.js | 1 + .../Attachments/AttachmentView/AttachmentViewPdf/index.ios.js | 1 + 3 files changed, 3 insertions(+) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index e0f3e9ab8454..c18e8a0e81aa 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -4,6 +4,7 @@ import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCa import PDFView from '@components/PDFView'; import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; + const propTypes = { /** Updates the scale value of the pdf */ updateScale: PropTypes.func, diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index 410badb229e8..058f79b746c7 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -7,6 +7,7 @@ import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propT import AttachmentCarouselPagerContext from '../../AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; + function AttachmentViewPdf(props) { const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); const scaleRef = useSharedValue(1); diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js index 94440e1d17cb..5f51d6a69953 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js @@ -11,6 +11,7 @@ function AttachmentViewPdf(props) { ); } + AttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; AttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; From 8fd691cac1ca22b7ab407900b80d6a50c08619cb Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 07:07:35 +0300 Subject: [PATCH 08/14] run prettier --- .../AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js | 1 - .../AttachmentView/AttachmentViewPdf/index.android.js | 1 - .../Attachments/AttachmentView/AttachmentViewPdf/index.ios.js | 1 - 3 files changed, 3 deletions(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index c18e8a0e81aa..e0f3e9ab8454 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -4,7 +4,6 @@ import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCa import PDFView from '@components/PDFView'; import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; - const propTypes = { /** Updates the scale value of the pdf */ updateScale: PropTypes.func, diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index 058f79b746c7..410badb229e8 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -7,7 +7,6 @@ import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propT import AttachmentCarouselPagerContext from '../../AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; - function AttachmentViewPdf(props) { const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); const scaleRef = useSharedValue(1); diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js index 5f51d6a69953..94440e1d17cb 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js @@ -11,7 +11,6 @@ function AttachmentViewPdf(props) { ); } - AttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; AttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; From 215cc1ab71d2a8bb64aa479f685d8e2d361c83b7 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 07:14:07 +0300 Subject: [PATCH 09/14] fix run prettier --- .../AttachmentView/AttachmentViewPdf/index.android.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index 410badb229e8..db5a841b9135 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -2,9 +2,9 @@ import React, {memo, useCallback, useContext} from 'react'; import {Gesture, GestureDetector} from 'react-native-gesture-handler'; import Animated, {useSharedValue} from 'react-native-reanimated'; import {View, StyleSheet} from 'react-native'; -import styles from '../../../../styles/styles'; +import styles from '@styles/styles'; import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propTypes'; -import AttachmentCarouselPagerContext from '../../AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; +import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; function AttachmentViewPdf(props) { From 310fead0a729c3eb09e24548653bc3a1b1dc29b9 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 07:21:34 +0300 Subject: [PATCH 10/14] fix addressed another prettier issue --- .../AttachmentView/AttachmentViewPdf/index.android.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index db5a841b9135..764fa836ff10 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -2,10 +2,10 @@ import React, {memo, useCallback, useContext} from 'react'; import {Gesture, GestureDetector} from 'react-native-gesture-handler'; import Animated, {useSharedValue} from 'react-native-reanimated'; import {View, StyleSheet} from 'react-native'; -import styles from '@styles/styles'; -import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propTypes'; import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; +import styles from '@styles/styles'; +import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propTypes'; function AttachmentViewPdf(props) { const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); From 67a31dc95bddbb256b967beb8803d745007e42b3 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 07:28:01 +0300 Subject: [PATCH 11/14] fix prettier --- .../AttachmentView/AttachmentViewPdf/index.android.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index 764fa836ff10..ed1906288bb5 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -3,8 +3,8 @@ import {Gesture, GestureDetector} from 'react-native-gesture-handler'; import Animated, {useSharedValue} from 'react-native-reanimated'; import {View, StyleSheet} from 'react-native'; import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; -import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; import styles from '@styles/styles'; +import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propTypes'; function AttachmentViewPdf(props) { From 1b9c80f0812eb48dc83aeb8dad0d29aef4a16037 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 13:11:23 +0300 Subject: [PATCH 12/14] fix prettier issue --- .../AttachmentView/AttachmentViewPdf/index.android.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index ed1906288bb5..3a5f39e188c7 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -1,7 +1,7 @@ import React, {memo, useCallback, useContext} from 'react'; +import {View, StyleSheet} from 'react-native'; import {Gesture, GestureDetector} from 'react-native-gesture-handler'; import Animated, {useSharedValue} from 'react-native-reanimated'; -import {View, StyleSheet} from 'react-native'; import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; import styles from '@styles/styles'; import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; From 892ea859e6aa3119fe073b0184a46fc06c875029 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 17:18:14 +0300 Subject: [PATCH 13/14] fix lint issues --- .../AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js | 2 +- .../AttachmentView/AttachmentViewPdf/index.android.js | 4 ++-- .../Attachments/AttachmentView/AttachmentViewPdf/index.ios.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index e0f3e9ab8454..c56bda69729f 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -1,5 +1,5 @@ -import React, {memo, useCallback, useContext, useEffect} from 'react'; import PropTypes from 'prop-types'; +import React, {memo, useCallback, useContext, useEffect} from 'react'; import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; import PDFView from '@components/PDFView'; import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index 3a5f39e188c7..7c3949f3f923 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -1,11 +1,11 @@ import React, {memo, useCallback, useContext} from 'react'; -import {View, StyleSheet} from 'react-native'; +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 {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propTypes'; +import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; function AttachmentViewPdf(props) { const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js index 94440e1d17cb..103ff292760f 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.ios.js @@ -1,6 +1,6 @@ import React, {memo} from 'react'; import BaseAttachmentViewPdf from './BaseAttachmentViewPdf'; -import {attachmentViewPdfPropTypes, attachmentViewPdfDefaultProps} from './propTypes'; +import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; function AttachmentViewPdf(props) { return ( From 7b5ec6b79dcff29d1fc0b303d2dbcd1ff3e5df73 Mon Sep 17 00:00:00 2001 From: Hezekiel Tamire Date: Mon, 30 Oct 2023 18:04:20 +0300 Subject: [PATCH 14/14] call updateScale in onScaleChanged instead of passing it as a prop --- .../BaseAttachmentViewPdf.js | 23 ++++--------------- .../AttachmentViewPdf/index.android.js | 8 +++++-- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js index c56bda69729f..40887ddee697 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/BaseAttachmentViewPdf.js @@ -1,21 +1,8 @@ -import PropTypes from 'prop-types'; import React, {memo, useCallback, useContext, useEffect} from 'react'; import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext'; import PDFView from '@components/PDFView'; import {attachmentViewPdfDefaultProps, attachmentViewPdfPropTypes} from './propTypes'; -const propTypes = { - /** Updates the scale value of the pdf */ - updateScale: PropTypes.func, - - ...attachmentViewPdfPropTypes, -}; - -const defaultProps = { - updateScale: () => {}, - ...attachmentViewPdfDefaultProps, -}; - function BaseAttachmentViewPdf({ file, encryptedSourceUrl, @@ -27,7 +14,6 @@ function BaseAttachmentViewPdf({ onLoadComplete, errorLabelStyles, style, - updateScale, }) { const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); @@ -41,8 +27,7 @@ function BaseAttachmentViewPdf({ const onScaleChanged = useCallback( (scale) => { - updateScale(scale); - onScaleChangedProp(); + onScaleChangedProp(scale); // When a pdf is shown in a carousel, we want to disable the pager scroll when the pdf is zoomed in if (isUsedInCarousel) { @@ -57,7 +42,7 @@ function BaseAttachmentViewPdf({ attachmentCarouselPagerContext.shouldPagerScroll.value = shouldPagerScroll; } }, - [attachmentCarouselPagerContext, isUsedInCarousel, onScaleChangedProp, updateScale], + [attachmentCarouselPagerContext, isUsedInCarousel, onScaleChangedProp], ); return ( @@ -75,8 +60,8 @@ function BaseAttachmentViewPdf({ ); } -BaseAttachmentViewPdf.propTypes = propTypes; -BaseAttachmentViewPdf.defaultProps = defaultProps; +BaseAttachmentViewPdf.propTypes = attachmentViewPdfPropTypes; +BaseAttachmentViewPdf.defaultProps = attachmentViewPdfDefaultProps; BaseAttachmentViewPdf.displayName = 'BaseAttachmentViewPdf'; export default memo(BaseAttachmentViewPdf); diff --git a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js index 7c3949f3f923..46afd23daa4c 100644 --- a/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewPdf/index.android.js @@ -8,6 +8,7 @@ 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); @@ -49,8 +50,11 @@ function AttachmentViewPdf(props) { > { + updateScale(scale); + onScaleChanged(); + }} />