You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[HOLD] [$250] [MEDIUM] Smartscan: Receipt thumbnail should show the top of the receipt #34120
changed the title [-][Wave 5] Receipt thumbnail should show the top of the receipt[/-][+][$500] [Wave 5] Receipt thumbnail should show the top of the receipt[/+]on Jan 9, 2024
Please re-state the problem that we are trying to solve in this issue.
Showing the middle portion of the receipt
What is the root cause of that problem?
For resizeMode cover, the image will have default positioning which is in the middle. The behavior that we want is similar to the object-position: top in CSS, but this React Native doesn't support it out of the box so we need to add it to React Native.
What changes do you think we should make in order to solve the problem?
Make the View wrapping the image to have overflow hidden, for the image itself, it will take full width, variable height according to the aspectRatio (not fixed height).
The View wrapper already has overflow hidden here so all we have to do is to make sure our Image component can handle the object position top case.
Add a objectPositionTop boolean prop to our Image component to control this behavior (later we can modify to support other positions like bottom). I intended to make it as similar and reusable as possible (similar usage as native object-position: top in CSS), we just need to modify in common Image component and we can use it everywhere we use images in the app.
Add the prop to ImageWithSizeCalculation as well and pass it through to the inner Image, In here, add objectPositionTop because we want that behavior for ThumbnailImage. We can make it a prop of ThumbnailImage as well so we can control the position of ThumbnailImage.
Then handle in Image so the objectPositionTop property works Here
For native platforms, we should do similarly in the index.native file, for native platforms, we won't get the image dimensions unless we load the image, we might want to use Image.getSize similar to on web to make sure it's independent from the image loading, and then we can prevent displaying of the image while the aspectRatio is not yet available, it might help prevent some potential issues.
We need to double check all possible cases of showing thumbnail receipt and add objectPositionTop to those places as needed.
What alternative solutions did you explore? (Optional)
Another approach is to translate the image vertically an amount such that instead of appearing from the center, image will appear at the top, this will require some math to calculate the translation so I prefer the aspectRatio approach above
I explored using object-position: top and background-position: top as well but react native does not yet support it.
Please re-state the problem that we are trying to solve in this issue.
Receipt thumbnail is not showing the top of the image
What is the root cause of that problem?
For displaying a receipt<ThumbnailImage/>component is used with shouldDynamicallyResize prop set to false. This causes the image to fill to the given container width and height. However the ImageWithSizeCalculation component covers the image to available width and height. This ensures that the displayed image properly covers the parent container. However a side effect of cover is that the image gets scaled and positioned such that it entirely covers the container, there by causing the vertical or horizontal alignment of image to be adjusted as needed.
What changes do you think we should make in order to solve the problem?
For always displaying the top section of receipt thumbnail, the image container width needs to be set to the width of thumbnail and the height should be set as per aspect ratio of the image. This makes sure that the thumbnail image gets rendered fully and not get scaled or repositioned due to 'cover'.
functionThumbnailImage({previewSourceURL, style, isAuthTokenRequired, imageWidth =200, imageHeight =200, shouldDynamicallyResize =true}: ThumbnailImageProps){// Use a variable to save container width on layoutconst[containerSize,setContainerSize]=useState({width: 0,height: 0});
...
// Now compute the aspect ratio of the imageconstaspectRatio=currentImageWidth&¤tImageHeight ? currentImageWidth/currentImageHeight : 1;// Compute aspect ratio of containerconstcontainerAspectRatio=containerSize.width/containerSize.height;// Get static image size as per aspect ratiosconstgetImageSize=useCallback(()=>{if(!aspectRatio){return[styles.w100,styles.h100]}if(aspectRatio>containerAspectRatio){return[{height: containerSize.height,width: containerSize.height*aspectRatio}]}return[{width: containerSize.width,height: containerSize.width/aspectRatio}]},[aspectRatio,containerAspectRatio,containerSize.height,containerSize.width,styles.h100,styles.w100])constsizeStyles=shouldDynamicallyResize ? [StyleUtils.getWidthAndHeightStyle(currentImageWidth??0,currentImageHeight)] : getImageSize();return(<Viewstyle={[style,styles.overflowHidden]}// Get container width onLayout={(e)=>setContainerSize(e.nativeEvent.layout)}><Viewstyle={[...sizeStyles,styles.alignItemsCenter,styles.justifyContentCenter]}><ImageWithSizeCalculationurl={previewSourceURL}onMeasure={updateImageSize}isAuthTokenRequired={isAuthTokenRequired}/></View></View>);
Above logic also handles images whose width is larger than height. Also the logic works for both native and web platforms.
There are a couple of screens like MoneyRequestConfirmationList and ReportActionItemImage etc where Image component is used instead of ThumbnailImage for displaying receipt. Such instances need to be replaced so that all occurrences of receipt image is properly displayed
Result
iOS
fix-ios_out.mp4
Web
fix-web_out.mp4
What alternative solutions did you explore? (Optional)
@aswin-s FYI your solution's the same as one of my alternate solution
A potential alternative is to make the View wrapping the image to have overflow hidden, for the image itself, it will take full width, variable height according to the aspectRatio (not fixed height).
I'm writing the implementation details for my proposal and updating soon
Please re-state the problem that we are trying to solve in this issue.
Receipt thumbnail is not showing the top of the image
What is the root cause of that problem?
Inside ReportActionItemImage, the ThumbnailImage component is being used. But this component uses 100% for height and width, which makes image center (looks like center but not exactly).
What changes do you think we should make in order to solve the problem?
We need to use aspectRatio technique to properly scale the images so that always top can be shown. We need to correctly scale the images for landscape, and portrait images.
Noted @dukenv0307. My proposal has just one approach detailed which works on all platforms. I've tested on both iOS and web and shared the screen grabs as well. I've also addressed scenarios like serving local image when receipt upload is in progress in the above video. So it is not exactly same or abstract like your proposal.
Activity
[-][Wave 5] Receipt thumbnail should show the top of the receipt[/-][+][$500] [Wave 5] Receipt thumbnail should show the top of the receipt[/+]melvin-bot commentedon Jan 9, 2024
Job added to Upwork: https://www.upwork.com/jobs/~019bb6b442f89fba02
melvin-bot commentedon Jan 9, 2024
Triggered auto assignment to @adelekennedy (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon Jan 9, 2024
Triggered auto assignment to Contributor-plus team member for initial proposal review - @cubuspl42 (
External)dukenv0307 commentedon Jan 9, 2024
Proposal
Please re-state the problem that we are trying to solve in this issue.
Showing the middle portion of the receipt
What is the root cause of that problem?
For
resizeModecover, the image will have default positioning which is in the middle. The behavior that we want is similar to theobject-position: topin CSS, but this React Native doesn't support it out of the box so we need to add it to React Native.What changes do you think we should make in order to solve the problem?
Make the View wrapping the image to have overflow hidden, for the image itself, it will take full width, variable height according to the
aspectRatio(not fixed height).The View wrapper already has overflow hidden here so all we have to do is to make sure our
Imagecomponent can handle the object position top case.objectPositionTopboolean prop to ourImagecomponent to control this behavior (later we can modify to support other positions likebottom). I intended to make it as similar and reusable as possible (similar usage as nativeobject-position: topin CSS), we just need to modify in commonImagecomponent and we can use it everywhere we use images in the app.ImageWithSizeCalculationas well and pass it through to the innerImage, In here, addobjectPositionTopbecause we want that behavior for ThumbnailImage. We can make it a prop ofThumbnailImageas well so we can control the position ofThumbnailImage.Imageso the objectPositionTop property worksHere
Here
Here
For native platforms, we should do similarly in the
index.nativefile, for native platforms, we won't get the image dimensions unless we load the image, we might want to useImage.getSizesimilar to on web to make sure it's independent from the image loading, and then we can prevent displaying of the image while theaspectRatiois not yet available, it might help prevent some potential issues.We need to double check all possible cases of showing thumbnail receipt and add
objectPositionTopto those places as needed.What alternative solutions did you explore? (Optional)
Another approach is to
translatethe image vertically an amount such that instead of appearing from the center, image will appear at the top, this will require some math to calculate the translation so I prefer theaspectRatioapproach aboveI explored using
object-position: topandbackground-position: topas well but react native does not yet support it.aswin-s commentedon Jan 9, 2024
Proposal
Please re-state the problem that we are trying to solve in this issue.
Receipt thumbnail is not showing the top of the image
What is the root cause of that problem?
For displaying a receipt
<ThumbnailImage/>component is used withshouldDynamicallyResizeprop set to false. This causes the image to fill to the given container width and height. However theImageWithSizeCalculationcomponent covers the image to available width and height. This ensures that the displayed image properly covers the parent container. However a side effect of cover is that the image gets scaled and positioned such that it entirely covers the container, there by causing the vertical or horizontal alignment of image to be adjusted as needed.What changes do you think we should make in order to solve the problem?
For always displaying the top section of receipt thumbnail, the image container width needs to be set to the width of thumbnail and the height should be set as per aspect ratio of the image. This makes sure that the thumbnail image gets rendered fully and not get scaled or repositioned due to 'cover'.
Above logic also handles images whose width is larger than height. Also the logic works for both native and web platforms.
There are a couple of screens like MoneyRequestConfirmationList and ReportActionItemImage etc where Image component is used instead of ThumbnailImage for displaying receipt. Such instances need to be replaced so that all occurrences of receipt image is properly displayed
Result
iOS
fix-ios_out.mp4
Web
fix-web_out.mp4
What alternative solutions did you explore? (Optional)
None (edited)
dukenv0307 commentedon Jan 9, 2024
@aswin-s FYI your solution's the same as one of my alternate solution
I'm writing the implementation details for my proposal and updating soon
shubham1206agra commentedon Jan 9, 2024
Proposal
Please re-state the problem that we are trying to solve in this issue.
Receipt thumbnail is not showing the top of the image
What is the root cause of that problem?
Inside
ReportActionItemImage, theThumbnailImagecomponent is being used. But this component uses100%for height and width, which makes image center (looks like center but not exactly).What changes do you think we should make in order to solve the problem?
We need to use
aspectRatiotechnique to properly scale the images so that always top can be shown. We need to correctly scale the images forlandscape, andportraitimages.Test branch - https://github.com/shubham1206agra/App/tree/test-thumbnail
Note - Naming of function is not final.
What alternative solutions did you explore? (Optional)
NA
aswin-s commentedon Jan 9, 2024
Noted @dukenv0307. My proposal has just one approach detailed which works on all platforms. I've tested on both iOS and web and shared the screen grabs as well. I've also addressed scenarios like serving local image when receipt upload is in progress in the above video. So it is not exactly same or abstract like your proposal.
I'll leave the merit of the proposal to the C+.
116 remaining items
Santhosh-Sellavel commentedon May 2, 2024
@mallenexpensify/@ad Can you assign me here please, seems I got unassigned accidentally
mallenexpensify commentedon May 3, 2024
Done, added @Santhosh-Sellavel , sorry about that
melvin-bot commentedon May 10, 2024
@Beamanator, @adelekennedy, @Santhosh-Sellavel, @dukenv0307 Whoops! This issue is 2 days overdue. Let's get this updated quick!
melvin-bot commentedon May 14, 2024
@Beamanator, @adelekennedy, @Santhosh-Sellavel, @dukenv0307 Still overdue 6 days?! Let's take care of this!
Beamanator commentedon May 14, 2024
Hmm @dukenv0307 your PR went to prod a week or so ago, are we waiting on anything here?
dukenv0307 commentedon May 15, 2024
@Beamanator We're waiting for payment here.
mallenexpensify commentedon May 19, 2024
Looks like this hit production on 4/23, so gonna pay
#35041 (comment)
Contributor: @dukenv0307 paid $250 via Upwork
Contributor+: @Santhosh-Sellavel owed $250 via NewDot