Skip to content

Commit

Permalink
Merge pull request #3487 from rdjuric/modalFix
Browse files Browse the repository at this point in the history
Fix PDF Attachments not scrollable
  • Loading branch information
ctkochan22 committed Jun 15, 2021
2 parents 11b7815 + c574127 commit a722ceb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const CONST = {
MODAL_TYPE: {
CONFIRM: 'confirm',
CENTERED: 'centered',
CENTERED_UNSWIPEABLE: 'centered_unswipeable',
BOTTOM_DOCKED: 'bottom_docked',
POPOVER: 'popover',
RIGHT_DOCKED: 'right_docked',
Expand Down
10 changes: 9 additions & 1 deletion src/components/AttachmentModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import Str from 'expensify-common/lib/str';
import {withOnyx} from 'react-native-onyx';
import CONST from '../CONST';
import Modal from './Modal';
Expand Down Expand Up @@ -97,10 +98,17 @@ class AttachmentModal extends PureComponent {
const attachmentViewStyles = this.props.isSmallScreenWidth
? [styles.imageModalImageCenterContainer]
: [styles.imageModalImageCenterContainer, styles.p5];

// If our attachment is a PDF, make the Modal unswipeable
const modalType = (this.state.sourceURL
&& (Str.isPDF(this.state.sourceURL) || (this.state.file
&& Str.isPDF(this.state.file.name || this.props.translate('attachmentView.unknownFilename')))))
? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE
: CONST.MODAL.MODAL_TYPE.CENTERED;
return (
<>
<Modal
type={CONST.MODAL.MODAL_TYPE.CENTERED}
type={modalType}
onSubmit={this.submitAndClose}
onClose={() => this.setState({isModalOpen: false})}
isVisible={this.state.isModalOpen}
Expand Down
1 change: 1 addition & 0 deletions src/components/Modal/BaseModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class BaseModal extends PureComponent {
}
this.props.onModalShow();
}}
propagateSwipe={this.props.propagateSwipe}
onModalHide={this.hideModalAndRemoveEventListeners}
onSwipeComplete={this.props.onClose}
swipeDirection={swipeDirection}
Expand Down
31 changes: 31 additions & 0 deletions src/styles/getModalStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ export default (type, windowDimensions, popoverAnchorPosition = {}) => {
animationOut = isSmallScreenWidth ? 'slideOutRight' : 'fadeOut';
shouldAddTopSafeAreaPadding = true;
break;
case CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE:
// A centered modal that cannot be dismissed with a swipe.
modalStyle = {
...modalStyle,
...{
alignItems: 'center',
},
};
modalContainerStyle = {
// Shadow Styles
shadowColor: colors.black,
shadowOffset: {
width: 0,
height: 0,
},
shadowOpacity: 0.1,
shadowRadius: 5,

flex: 1,
marginTop: isSmallScreenWidth ? 0 : 20,
marginBottom: isSmallScreenWidth ? 0 : 20,
borderRadius: isSmallScreenWidth ? 0 : 12,
borderWidth: isSmallScreenWidth ? 1 : 0,
overflow: 'hidden',
width: isSmallScreenWidth ? '100%' : windowWidth - 40,
};
swipeDirection = undefined;
animationIn = isSmallScreenWidth ? 'slideInRight' : 'fadeIn';
animationOut = isSmallScreenWidth ? 'slideOutRight' : 'fadeOut';
shouldAddTopSafeAreaPadding = true;
break;
case CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED:
modalStyle = {
...modalStyle,
Expand Down

0 comments on commit a722ceb

Please sign in to comment.