Skip to content

Commit

Permalink
adding a native press event for pdfs
Browse files Browse the repository at this point in the history
  • Loading branch information
JediWattson committed Aug 13, 2022
1 parent 191d8d7 commit 91a5a05
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/components/AttachmentCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'lodash';
import Str from 'expensify-common/lib/str';
import Button from './Button';
import * as Expensicons from './Icon/Expensicons';
import styles from '../styles/styles';
Expand Down Expand Up @@ -39,6 +38,7 @@ class AttachmentCarousel extends React.Component {
super(props);

this.canUseTouchScreen = canUseTouchScreen();
this.onPressShowArrow = this.onPressShowArrow.bind(this);
this.cycleThroughAttachments = this.cycleThroughAttachments.bind(this);
this.handleArrowPress = this.handleArrowPress.bind(this);
this.onShowArrow = this.onShowArrow.bind(this);
Expand Down Expand Up @@ -97,6 +97,16 @@ class AttachmentCarousel extends React.Component {
this.setState({showArrows});
}

/**
* Helper to provide a check for touchscreens
*/
onPressShowArrow() {
if (!this.canUseTouchScreen) {
return;
}
this.onShowArrow(!this.state.showArrows);
}

/**
* Helps to navigate between next/previous attachments
* @param {Object} attachmentItem
Expand Down Expand Up @@ -154,7 +164,7 @@ class AttachmentCarousel extends React.Component {
onMouseEnter={() => this.onShowArrow(true)}
onMouseLeave={() => this.onShowArrow(false)}
>
{(this.state.showArrows || Str.isPDF(this.state.sourceURL)) && (
{this.state.showArrows && (
<>
<Button
medium
Expand Down Expand Up @@ -183,7 +193,7 @@ class AttachmentCarousel extends React.Component {
onPress={() => this.canUseTouchScreen && this.onShowArrow(!this.state.showArrows)}
onSwipeHorizontal={this.cycleThroughAttachments}
>
<AttachmentView sourceURL={this.state.sourceURL} file={this.state.file} />
<AttachmentView onPDFPress={this.onPressShowArrow} sourceURL={this.state.sourceURL} file={this.state.file} />
</SwipeableView>
</View>

Expand Down
5 changes: 5 additions & 0 deletions src/components/AttachmentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const propTypes = {
/** Flag to show the loading indicator */
shouldShowLoadingSpinnerIcon: PropTypes.bool,

/** Function for native pdf to handle toggling arrows */
onPDFPress: PropTypes.func,

...withLocalizePropTypes,
};

Expand All @@ -37,6 +40,7 @@ const defaultProps = {
},
shouldShowDownloadIcon: false,
shouldShowLoadingSpinnerIcon: false,
onPDFPress: () => {},
};

const AttachmentView = (props) => {
Expand All @@ -46,6 +50,7 @@ const AttachmentView = (props) => {
|| (props.file && Str.isPDF(props.file.name || props.translate('attachmentView.unknownFilename')))) {
return (
<PDFView
onPress={props.onPDFPress}
sourceURL={props.sourceURL}
style={styles.imageModalPDF}
/>
Expand Down
6 changes: 5 additions & 1 deletion src/components/PDFView/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ const propTypes = {
// eslint-disable-next-line react/forbid-prop-types
style: PropTypes.any,

/** handles press events like toggling attachment arrows natively */
onPress: PropTypes.func,

...windowDimensionsPropTypes,
};

const defaultProps = {
sourceURL: '',
style: {},
onPress: () => {},
};

/**
Expand All @@ -31,7 +35,7 @@ const defaultProps = {
*/

const PDFView = props => (
<TouchableWithoutFeedback style={[styles.flex1, props.style]}>
<TouchableWithoutFeedback onPress={props.onPress} style={[styles.flex1, props.style]}>
<PDF
activityIndicator={<FullScreenLoadingIndicator />}
source={{uri: props.sourceURL}}
Expand Down

0 comments on commit 91a5a05

Please sign in to comment.