Skip to content
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

fix(native-app): fix document pdf rendering #16449

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions apps/native/app/src/screens/document-detail/document-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{
const hasConfirmation = !!Document.confirmation
const hasAlert =
!!Document.alert && (Document.alert?.title || Document.alert?.data)
const showAlert =
const showAdditionalInfo =
showConfirmedAlert ||
(hasAlert && !hasConfirmation) ||
(hasActions && !showConfirmationAlert)
(hasActions && !showConfirmedAlert && !hasConfirmation)

const loading = docRes.loading || !accessToken
const fileTypeLoaded = !!Document?.content?.type
Expand Down Expand Up @@ -438,7 +438,7 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{
label={isUrgent ? intl.formatMessage({ id: 'inbox.urgent' }) : ''}
/>
</Host>
{showAlert && (
{showAdditionalInfo && (
<ActionsWrapper>
{showConfirmedAlert && (
<Alert
Expand Down Expand Up @@ -487,27 +487,24 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{
/>
) : hasPdf ? (
<PdfWrapper>
{visible &&
accessToken &&
(shouldIncludeDocument ||
(!shouldIncludeDocument && showAlert)) && (
<PdfViewer
url={`data:application/pdf;base64,${Document.content?.value}`}
body={`documentId=${Document.id}&__accessToken=${accessToken}`}
onLoaded={(filePath: any) => {
setPdfUrl(filePath)
// Make sure to not set document as loaded until actions have been fetched
// To prevent top of first page not being shown
if (shouldIncludeDocument) {
setLoaded(true)
}
}}
onError={() => {
{visible && accessToken && loaded && (
<PdfViewer
url={`data:application/pdf;base64,${Document.content?.value}`}
body={`documentId=${Document.id}&__accessToken=${accessToken}`}
onLoaded={(filePath: any) => {
setPdfUrl(filePath)
// Make sure to not set document as loaded until actions have been fetched
// To prevent top of first page not being shown
if (shouldIncludeDocument) {
setLoaded(true)
setError(true)
}}
/>
)}
}
}}
onError={() => {
setLoaded(true)
setError(true)
}}
/>
)}
</PdfWrapper>
) : (
<WebView
Expand Down
Loading