Skip to content

Commit c70c52b

Browse files
authored
Merge pull request Expensify#88209 from software-mansion-labs/mrejdak/fix-zoom-on-rotate
2 parents 76f15c5 + 3a9ebb8 commit c70c52b

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/components/PDFView/index.native.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import useKeyboardState from '@hooks/useKeyboardState';
99
import useLocalize from '@hooks/useLocalize';
1010
import useOnyx from '@hooks/useOnyx';
1111
import useResponsiveLayout from '@hooks/useResponsiveLayout';
12+
import useSafeAreaPaddings from '@hooks/useSafeAreaPaddings';
1213
import useStyleUtils from '@hooks/useStyleUtils';
1314
import useThemeStyles from '@hooks/useThemeStyles';
1415
import useWindowDimensions from '@hooks/useWindowDimensions';
@@ -52,6 +53,7 @@ function PDFView({onToggleKeyboard, onLoadComplete, fileName, onPress, isFocused
5253
const themeStyles = useThemeStyles();
5354
const {isKeyboardShown} = useKeyboardState();
5455
const StyleUtils = useStyleUtils();
56+
const {insets} = useSafeAreaPaddings();
5557

5658
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
5759

@@ -152,9 +154,14 @@ function PDFView({onToggleKeyboard, onLoadComplete, fileName, onPress, isFocused
152154
);
153155

154156
function renderPDFView() {
155-
const pdfWidth = isUsedAsChatAttachment ? LOADING_THUMBNAIL_WIDTH : windowWidth;
157+
// Insets are used to adjust the maxWidth of the PDF view in landscape mode
158+
const pdfWidth = isUsedAsChatAttachment ? LOADING_THUMBNAIL_WIDTH : windowWidth - insets.left - insets.right;
156159
const pdfHeight = isUsedAsChatAttachment ? LOADING_THUMBNAIL_HEIGHT : windowHeight;
157-
const pdfStyles: StyleProp<ViewStyle> = [themeStyles.imageModalPDF, StyleUtils.getWidthAndHeightStyle(pdfWidth, pdfHeight)];
160+
161+
const pdfStyles: StyleProp<ViewStyle> = [
162+
themeStyles.imageModalPDF,
163+
isUsedAsChatAttachment ? StyleUtils.getWidthAndHeightStyle(pdfWidth, pdfHeight) : StyleUtils.getPDFViewStyle(pdfWidth, pdfHeight),
164+
];
158165

159166
// If we haven't yet successfully validated the password and loaded the PDF,
160167
// then we need to hide the react-native-pdf/PDF component so that PDFPasswordForm

src/styles/utils/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,15 @@ function getBackgroundColorWithOpacityStyle(backgroundColor: string, opacity: nu
546546
return {};
547547
}
548548

549+
function getPDFViewStyle(width: number, height: number): Pick<ViewStyle, 'height' | 'width' | 'maxWidth' | 'maxHeight'> {
550+
return {
551+
width: '100%',
552+
height: '100%',
553+
maxWidth: width,
554+
maxHeight: height,
555+
};
556+
}
557+
549558
function getWidthAndHeightStyle(width: number, height?: number): Pick<ViewStyle, 'height' | 'width'> {
550559
return {
551560
width,
@@ -1400,6 +1409,7 @@ const staticStyleUtils = {
14001409
getTextColorStyle,
14011410
getTransparentColor,
14021411
getWidthAndHeightStyle,
1412+
getPDFViewStyle,
14031413
getWidthStyle,
14041414
getWrappingStyle,
14051415
getZoomSizingStyle,

0 commit comments

Comments
 (0)