-
Notifications
You must be signed in to change notification settings - Fork 3k
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: IOU Scan - In dark mode, the damaged PDF - file is barely visible. #40607
Changes from 16 commits
df364c5
1b4bf57
1e046d8
2288b18
24577f1
f258c08
dbc3286
d6a166b
8745bc8
bbcea3c
eb01458
2eeadec
31caba2
601eb77
075868d
dc778d7
1f93a1e
16cb64f
364acd6
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import Icon from '@components/Icon'; | ||
import * as Expensicons from '@components/Icon/Expensicons'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import variables from '@styles/variables'; | ||
|
||
function PDFThumbnailError() { | ||
const styles = useThemeStyles(); | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<View style={[styles.justifyContentCenter, styles.pdfErrorPlaceholder, styles.alignItemsCenter]}> | ||
<Icon | ||
src={Expensicons.ReceiptSlash} | ||
width={variables.receiptPlaceholderIconWidth} | ||
height={variables.receiptPlaceholderIconHeight} | ||
fill={theme.icon} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
export default PDFThumbnailError; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import pdfWorkerSource from 'pdfjs-dist/legacy/build/pdf.worker'; | ||
import React, {useMemo} from 'react'; | ||
import React, {useMemo, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import {Document, pdfjs, Thumbnail} from 'react-pdf'; | ||
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; | ||
import PDFThumbnailError from './PDFThumbnailError'; | ||
import type PDFThumbnailProps from './types'; | ||
|
||
if (!pdfjs.GlobalWorkerOptions.workerSrc) { | ||
pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'})); | ||
} | ||
|
||
function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword}: PDFThumbnailProps) { | ||
function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword, onLoadError}: PDFThumbnailProps) { | ||
const styles = useThemeStyles(); | ||
const [failedToLoad, setFailedToLoad] = useState(false); | ||
|
||
const thumbnail = useMemo( | ||
() => ( | ||
|
@@ -25,18 +27,31 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena | |
}} | ||
externalLinkTarget="_blank" | ||
onPassword={onPassword} | ||
onLoad={() => { | ||
setFailedToLoad(false); | ||
}} | ||
onLoadError={() => { | ||
if (onLoadError) { | ||
onLoadError(); | ||
} | ||
setFailedToLoad(true); | ||
}} | ||
error={() => null} | ||
> | ||
<View pointerEvents="none"> | ||
<Thumbnail pageIndex={0} /> | ||
</View> | ||
</Document> | ||
), | ||
[isAuthTokenRequired, previewSourceURL, onPassword], | ||
[isAuthTokenRequired, previewSourceURL, onPassword, onLoadError], | ||
); | ||
|
||
return ( | ||
<View style={[style, styles.overflowHidden]}> | ||
<View style={[styles.w100, styles.h100, styles.alignItemsCenter, styles.justifyContentCenter]}>{enabled && thumbnail}</View> | ||
<View style={[style, styles.h100, styles.overflowHidden]}> | ||
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. Here, we Added the 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. I found a bug when adding |
||
<View style={[styles.w100, styles.h100, !failedToLoad && {...styles.alignItemsCenter, ...styles.justifyContentCenter}]}> | ||
{enabled && failedToLoad && thumbnail} | ||
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. These conditionals contradict each other. Why should we show a thumbnail when the failedToLoad condition is true?? 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. thats incorrect, updated now. Thanks for the catch. |
||
{failedToLoad && <PDFThumbnailError />} | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB: If we replace the wording from Image to Attachment for the translate key, should we change the function name to
showAttachmentCorruptionAlert
?