@@ -21,29 +21,26 @@ function releaseUri(uri: string) {
2121}
2222
2323/**
24- * Pre-populate the thumbnail cache so the confirm screen can use it
24+ * Pre-populate the receipt-image cache so the confirm screen can use it
2525 * synchronously on first render, avoiding any source swap / flash.
2626 */
27- function pregenerateThumbnail ( sourceUri : string ) : Promise < string | undefined > {
27+ function precacheReceiptImage ( sourceUri : string ) : Promise < string | undefined > {
2828 if ( thumbnailCache . has ( sourceUri ) ) {
2929 return Promise . resolve ( thumbnailCache . get ( sourceUri ) ) ;
3030 }
31- return generateThumbnail ( sourceUri ) . then ( ( uri ) => {
32- if ( uri ) {
33- thumbnailCache . set ( sourceUri , uri ) ;
34- // Pre-decode the thumbnail in the native image pipeline so the
35- // confirmation screen can display it instantly without decode latency.
36- Image . prefetch ( uri ) ;
37- }
38- return uri ;
39- } ) ;
31+ thumbnailCache . set ( sourceUri , sourceUri ) ;
32+ // Pre-decode the image in the native image pipeline so the
33+ // confirmation screen can display it instantly without decode latency.
34+ return Image . prefetch ( sourceUri )
35+ . then ( ( ) => sourceUri )
36+ . catch ( ( ) => sourceUri ) ;
4037}
4138
4239/**
43- * Returns a cached low-resolution thumbnail for a local receipt image.
44- * The thumbnail should be pre-generated via `pregenerateThumbnail ` before
45- * navigating to the confirm screen. If it wasn't, this hook generates it
46- * as a fallback, but in that case a source swap (flash) may occur.
40+ * Returns a cached receipt image URI for a local receipt. The image should be
41+ * pre-cached via `precacheReceiptImage ` before navigating to the confirm screen.
42+ * If it wasn't, this hook generates a thumbnail as a fallback, but in that case
43+ * a source swap (flash) may occur.
4744 */
4845function useLocalReceiptThumbnail ( sourceUri : string | undefined , isLocalFile : boolean ) : { thumbnailUri : string | undefined ; isGenerating : boolean } {
4946 const [ asyncResult , setAsyncResult ] = useState < { source : string ; uri ?: string ; done : boolean } | undefined > ( ) ;
@@ -109,5 +106,5 @@ function useLocalReceiptThumbnail(sourceUri: string | undefined, isLocalFile: bo
109106 return { thumbnailUri, isGenerating} ;
110107}
111108
112- export { pregenerateThumbnail } ;
109+ export { precacheReceiptImage } ;
113110export default useLocalReceiptThumbnail ;
0 commit comments