-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Report Attachments Modal Route #20167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7b00c12
1aec799
eb3e092
2c758a4
236df33
2b164e9
ca27f0d
d5c6e4c
3d5bc85
f08d740
305fcc4
5b3be9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import React from 'react'; | ||
| import Navigation from '../../../libs/Navigation/Navigation'; | ||
| import htmlRendererPropTypes from './htmlRendererPropTypes'; | ||
| import AttachmentModal from '../../AttachmentModal'; | ||
| import styles from '../../../styles/styles'; | ||
| import ThumbnailImage from '../../ThumbnailImage'; | ||
| import PressableWithoutFocus from '../../Pressable/PressableWithoutFocus'; | ||
|
|
@@ -9,6 +9,7 @@ import {ShowContextMenuContext, showContextMenuForReport} from '../../ShowContex | |
| import tryResolveUrlFromApiRoot from '../../../libs/tryResolveUrlFromApiRoot'; | ||
| import * as ReportUtils from '../../../libs/ReportUtils'; | ||
| import withLocalize, {withLocalizePropTypes} from '../../withLocalize'; | ||
| import ROUTES from '../../../ROUTES'; | ||
|
|
||
| const propTypes = {...htmlRendererPropTypes, ...withLocalizePropTypes}; | ||
|
|
||
|
|
@@ -33,7 +34,6 @@ function ImageRenderer(props) { | |
| // control and thus require no authToken to verify access. | ||
| // | ||
| const isAttachment = Boolean(htmlAttribs[CONST.ATTACHMENT_SOURCE_ATTRIBUTE]); | ||
| const originalFileName = htmlAttribs['data-name']; | ||
|
|
||
| // Files created/uploaded/hosted by App should resolve from API ROOT. Other URLs aren't modified | ||
| const previewSource = tryResolveUrlFromApiRoot(htmlAttribs.src); | ||
|
|
@@ -54,31 +54,24 @@ function ImageRenderer(props) { | |
| ) : ( | ||
| <ShowContextMenuContext.Consumer> | ||
| {({anchor, report, action, checkIfContextMenuActive}) => ( | ||
| <AttachmentModal | ||
| allowDownload | ||
| report={report} | ||
| source={source} | ||
| isAuthTokenRequired={isAttachment} | ||
| originalFileName={originalFileName} | ||
| <PressableWithoutFocus | ||
| style={[styles.noOutline]} | ||
| onPress={() => { | ||
| const route = ROUTES.getReportAttachmentRoute(report.reportID, source); | ||
| Navigation.navigate(route); | ||
|
Comment on lines
60
to
61
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be replaced by a call to Everywhere else we use |
||
| }} | ||
| onLongPress={(event) => showContextMenuForReport(event, anchor, report.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report))} | ||
| accessibilityRole="imagebutton" | ||
| accessibilityLabel={props.translate('accessibilityHints.viewAttachment')} | ||
| > | ||
| {({show}) => ( | ||
| <PressableWithoutFocus | ||
| style={[styles.noOutline]} | ||
| onPress={show} | ||
| onLongPress={(event) => showContextMenuForReport(event, anchor, report.reportID, action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report))} | ||
| accessibilityRole="imagebutton" | ||
| accessibilityLabel={props.translate('accessibilityHints.viewAttachment')} | ||
| > | ||
| <ThumbnailImage | ||
| previewSourceURL={previewSource} | ||
| style={styles.webViewStyles.tagStyles.img} | ||
| isAuthTokenRequired={isAttachment} | ||
| imageWidth={imageWidth} | ||
| imageHeight={imageHeight} | ||
| /> | ||
| </PressableWithoutFocus> | ||
| )} | ||
| </AttachmentModal> | ||
| <ThumbnailImage | ||
| previewSourceURL={previewSource} | ||
| style={styles.webViewStyles.tagStyles.img} | ||
| isAuthTokenRequired={isAttachment} | ||
| imageWidth={imageWidth} | ||
| imageHeight={imageHeight} | ||
| /> | ||
| </PressableWithoutFocus> | ||
| )} | ||
| </ShowContextMenuContext.Consumer> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,6 +261,18 @@ class AuthScreens extends React.Component { | |
| return ConciergePage; | ||
| }} | ||
| /> | ||
| <RootStack.Screen | ||
| name={SCREENS.REPORT_ATTACHMENTS} | ||
| options={{ | ||
| headerShown: false, | ||
| presentation: 'transparentModal', | ||
| }} | ||
| getComponent={() => { | ||
| const ReportAttachments = require('../../../pages/home/report/ReportAttachments').default; | ||
| return ReportAttachments; | ||
| }} | ||
| listeners={modalScreenListeners} | ||
| /> | ||
|
Comment on lines
+264
to
+275
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Utilizing Sample Behavior When Not Using
|
||
| <RootStack.Screen | ||
| name={NAVIGATORS.FULL_SCREEN_NAVIGATOR} | ||
| options={defaultScreenOptions} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import navigationRef from './navigationRef'; | |
| import NAVIGATORS from '../../NAVIGATORS'; | ||
| import originalGetTopmostReportId from './getTopmostReportId'; | ||
| import getStateFromPath from './getStateFromPath'; | ||
| import SCREENS from '../../SCREENS'; | ||
|
|
||
| let resolveNavigationIsReadyPromise; | ||
| const navigationIsReadyPromise = new Promise((resolve) => { | ||
|
|
@@ -127,19 +128,24 @@ function dismissModal(targetReportID) { | |
| } | ||
| const rootState = navigationRef.getRootState(); | ||
| const lastRoute = _.last(rootState.routes); | ||
| if (lastRoute.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR || lastRoute.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR) { | ||
| // if we are not in the target report, we need to navigate to it after dismissing the modal | ||
| if (targetReportID && targetReportID !== getTopmostReportId(rootState)) { | ||
| const state = getStateFromPath(ROUTES.getReportRoute(targetReportID)); | ||
|
|
||
| const action = getActionFromState(state, linkingConfig.config); | ||
| action.type = 'REPLACE'; | ||
| navigationRef.current.dispatch(action); | ||
| } else { | ||
| navigationRef.current.dispatch({...StackActions.pop(), target: rootState.key}); | ||
| switch (lastRoute.name) { | ||
| case NAVIGATORS.RIGHT_MODAL_NAVIGATOR: | ||
| case NAVIGATORS.FULL_SCREEN_NAVIGATOR: | ||
| case SCREENS.REPORT_ATTACHMENTS: | ||
| // if we are not in the target report, we need to navigate to it after dismissing the modal | ||
| if (targetReportID && targetReportID !== getTopmostReportId(rootState)) { | ||
| const state = getStateFromPath(ROUTES.getReportRoute(targetReportID)); | ||
|
|
||
| const action = getActionFromState(state, linkingConfig.config); | ||
| action.type = 'REPLACE'; | ||
| navigationRef.current.dispatch(action); | ||
| } else { | ||
| navigationRef.current.dispatch({...StackActions.pop(), target: rootState.key}); | ||
| } | ||
| break; | ||
| default: { | ||
| Log.hmmm('[Navigation] dismissModal failed because there is no modal stack to dismiss'); | ||
|
Comment on lines
+131
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nicely done! |
||
| } | ||
| } else { | ||
| Log.hmmm('[Navigation] dismissModal failed because there is no modal stack to dismiss'); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import React from 'react'; | ||
| import _ from 'underscore'; | ||
| import PropTypes from 'prop-types'; | ||
| import AttachmentModal from '../../../components/AttachmentModal'; | ||
| import Navigation from '../../../libs/Navigation/Navigation'; | ||
| import * as ReportUtils from '../../../libs/ReportUtils'; | ||
|
|
||
| const propTypes = { | ||
| /** Navigation route context info provided by react navigation */ | ||
| route: PropTypes.shape({ | ||
| /** Route specific parameters used on this screen */ | ||
| params: PropTypes.shape({ | ||
| /** The report ID which the attachment is associated with */ | ||
| reportID: PropTypes.string.isRequired, | ||
| /** The uri encoded source of the attachment */ | ||
| source: PropTypes.string.isRequired, | ||
| }).isRequired, | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| function ReportAttachments(props) { | ||
| const reportID = _.get(props, ['route', 'params', 'reportID']); | ||
| const report = ReportUtils.getReport(reportID); | ||
| const source = decodeURI(_.get(props, ['route', 'params', 'source'])); | ||
|
Comment on lines
+22
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB: these can all be used inline instead of declared separately
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| return ( | ||
| <AttachmentModal | ||
| allowDownload | ||
| defaultOpen | ||
| report={report} | ||
| source={source} | ||
| onModalHide={() => Navigation.dismissModal(reportID)} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| ReportAttachments.propTypes = propTypes; | ||
| ReportAttachments.displayName = 'ReportAttachments'; | ||
|
|
||
| export default ReportAttachments; | ||
Uh oh!
There was an error while loading. Please reload this page.