-
Notifications
You must be signed in to change notification settings - Fork 3.9k
add full screen loading indicator context #59519
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
Merged
mountiny
merged 5 commits into
Expensify:main
from
callstack-internal:fullscreen-loader-context
Apr 7, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6feb771
create context that holds the full screen loader
TMisiukiewicz 16ff62a
use fullscreen context in IOURequestStepScan
TMisiukiewicz e031310
Merge remote-tracking branch 'upstream/main' into fullscreen-loader-c…
TMisiukiewicz 25181b5
add docs to types
TMisiukiewicz 1e3b950
Merge remote-tracking branch 'upstream/main' into fullscreen-loader-c…
TMisiukiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import React, {createContext, useContext, useMemo, useState} from 'react'; | ||
| import type {ReactNode} from 'react'; | ||
| import FullScreenLoadingIndicator from './FullscreenLoadingIndicator'; | ||
|
|
||
| type FullScreenLoaderContextType = { | ||
| /** | ||
| * Whether the full screen loader is visible. | ||
| */ | ||
| isLoaderVisible: boolean; | ||
| /** | ||
| * Set the full screen loader visibility. | ||
| */ | ||
| setIsLoaderVisible: React.Dispatch<React.SetStateAction<boolean>>; | ||
| }; | ||
|
|
||
| const FullScreenLoaderContext = createContext<FullScreenLoaderContextType>({ | ||
| isLoaderVisible: false, | ||
| setIsLoaderVisible: () => {}, | ||
| }); | ||
|
|
||
| type FullScreenLoaderContextProviderProps = { | ||
| /** | ||
| * The children of the full screen loader context provider. | ||
| */ | ||
| children: ReactNode; | ||
| }; | ||
|
|
||
| function FullScreenLoaderContextProvider({children}: FullScreenLoaderContextProviderProps) { | ||
| const [isLoaderVisible, setIsLoaderVisible] = useState(false); | ||
|
|
||
| const loaderContext = useMemo( | ||
| () => ({ | ||
| isLoaderVisible, | ||
| setIsLoaderVisible, | ||
| }), | ||
| [isLoaderVisible], | ||
| ); | ||
|
|
||
| return ( | ||
| <FullScreenLoaderContext.Provider value={loaderContext}> | ||
| {children} | ||
| {isLoaderVisible && <FullScreenLoadingIndicator />} | ||
| </FullScreenLoaderContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| function useFullScreenLoader() { | ||
| const context = useContext(FullScreenLoaderContext); | ||
|
|
||
| if (!context) { | ||
| throw new Error('useFullScreenLoader must be used within a FullScreenLoaderContextProvider'); | ||
| } | ||
|
|
||
| return context; | ||
| } | ||
|
|
||
| FullScreenLoaderContextProvider.displayName = 'FullScreenLoaderContextProvider'; | ||
|
|
||
| export default FullScreenLoaderContextProvider; | ||
| export {FullScreenLoaderContext, useFullScreenLoader}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ import Shutter from '@assets/images/shutter.svg'; | |
| import type {FileObject} from '@components/AttachmentModal'; | ||
| import AttachmentPicker from '@components/AttachmentPicker'; | ||
| import Button from '@components/Button'; | ||
| import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; | ||
| import {useFullScreenLoader} from '@components/FullScreenLoaderContext'; | ||
| import Icon from '@components/Icon'; | ||
| import * as Expensicons from '@components/Icon/Expensicons'; | ||
| import ImageSVG from '@components/ImageSVG'; | ||
|
|
@@ -81,6 +81,7 @@ function IOURequestStepScan({ | |
| }: IOURequestStepScanProps) { | ||
| const theme = useTheme(); | ||
| const styles = useThemeStyles(); | ||
| const {isLoaderVisible, setIsLoaderVisible} = useFullScreenLoader(); | ||
| const device = useCameraDevice('back', { | ||
| physicalDevices: ['wide-angle-camera', 'ultra-wide-angle-camera'], | ||
| }); | ||
|
|
@@ -105,7 +106,6 @@ function IOURequestStepScan({ | |
| const isPlatformMuted = mutedPlatforms[platform]; | ||
| const [cameraPermissionStatus, setCameraPermissionStatus] = useState<string | null>(null); | ||
| const [didCapturePhoto, setDidCapturePhoto] = useState(false); | ||
| const [isLoadingReceipt, setIsLoadingReceipt] = useState(false); | ||
| const isTabActive = useIsFocused(); | ||
|
|
||
| const [pdfFile, setPdfFile] = useState<null | FileObject>(null); | ||
|
|
@@ -203,8 +203,12 @@ function IOURequestStepScan({ | |
|
|
||
| return () => { | ||
| subscription.remove(); | ||
|
|
||
| if (isLoaderVisible) { | ||
| setIsLoaderVisible(false); | ||
| } | ||
| }; | ||
| }, []), | ||
| }, [isLoaderVisible, setIsLoaderVisible]), | ||
| ); | ||
|
|
||
| const validateReceipt = (file: FileObject) => { | ||
|
|
@@ -551,13 +555,7 @@ function IOURequestStepScan({ | |
| return; | ||
| } | ||
|
|
||
| // With the image size > 24MB, we use manipulateAsync to resize the image. | ||
| // It takes a long time so we should display a loading indicator while the resize image progresses. | ||
| if (Str.isImage(originalFile.name ?? '') && (originalFile?.size ?? 0) > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { | ||
| setIsLoadingReceipt(true); | ||
| } | ||
| resizeImageIfNeeded(originalFile).then((file) => { | ||
| setIsLoadingReceipt(false); | ||
| // Store the receipt on the transaction object in Onyx | ||
| // On Android devices, fetching blob for a file with name containing spaces fails to retrieve the type of file. | ||
| // So, let us also save the file type in receipt for later use during blob fetch | ||
|
|
@@ -702,7 +700,6 @@ function IOURequestStepScan({ | |
| setElementTop(e.nativeEvent.layout.height - (variables.tabSelectorButtonHeight + variables.tabSelectorButtonPadding) * 2); | ||
| }} | ||
| > | ||
| {isLoadingReceipt && <FullScreenLoadingIndicator />} | ||
| {!!pdfFile && ( | ||
| <PDFThumbnail | ||
| style={styles.invisiblePDF} | ||
|
|
@@ -786,7 +783,7 @@ function IOURequestStepScan({ | |
| </EducationalTooltip> | ||
|
|
||
| <View style={[styles.flexRow, styles.justifyContentAround, styles.alignItemsCenter, styles.pv3]}> | ||
| <AttachmentPicker> | ||
| <AttachmentPicker onOpenPicker={() => setIsLoaderVisible(true)}> | ||
| {({openPicker}) => ( | ||
| <PressableWithFeedback | ||
| role={CONST.ROLE.BUTTON} | ||
|
|
@@ -795,6 +792,7 @@ function IOURequestStepScan({ | |
| onPress={() => { | ||
| openPicker({ | ||
| onPicked: (data) => setReceiptAndNavigate(data.at(0) ?? {}), | ||
| onCanceled: () => setIsLoaderVisible(false), | ||
|
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.
|
||
| }); | ||
| }} | ||
| > | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
here too