-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add LoadingProvider to the app #1105
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 8000 of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e130254
to
f018ee3
Compare
Like the documentation and PR description a lot. It seems like we have now two approach to display something "above everything" :
My opinion is that for the moment it is good to try both to see advantages/drawbacks. |
Both approaches have their pros and their cons. @acezard 's implementation seems great since the Overlay is displayed directly from the Provider component. This was not possible for Events based way has the advantage of easily preventing react's rerenders and can be called from everywhere (even from out-of-react methods), but the main drawback is that we don't rely on React's mechanisms anymore and we are drifting towards an object/event based application instead of a functional one. My questions about the Overlay implement are the following:
|
f018ee3
to
025cc4c
Compare
I decided to place it directly under the
Yes it is needed. That's why the provider should be above the Here is the implementation export const useShareFiles = (): (() => Promise<void>) => {
const { showOverlay, hideOverlay } = useLoadingOverlay()
const { handleError } = useError()
const { t } = useI18n()
const client = useClient()
return async (arg = ''): Promise<void> => {
const fileIds = JSON.parse(arg) as string[]
try {
showOverlay()
if (!client) throw new Error('Client is undefined')
await fetchFilesByIds(client, fileIds)
} catch (error) {
if (getErrorMessage(error) === 'User did not share') return
handleError(
t('errors.shareFiles', {
postProcess: 'interval',
count: fileIds.length
})
)
OsReceiveLogger.error('useShareFiles: error', error)
} finally {
hideOverlay()
}
}
} const InnerNav = ({ client, setClient }) => {
const shareFiles = useShareFiles()
return (
<NativeIntentProvider
localMethods={localMethods(client, {
shareFiles
})}
>
)
}
It calls a render cycle only on component consuming the context values returned by the hook. Other children components are not expected to get a render cycle, in theory or in some tests I did (if HomeView use the hook, HomeScreen isn't triggering a render when we hide the overlay) |
025cc4c
to
b3eb221
Compare
Extracting logic
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.
We still have to move the LockScreenWrapper (and its corresponding SafeAreaProvider)on top of the LoadingOverlay but everything else is good 👍
useLoadingOverlay
Hook DocumentationOverview
The
useLoadingOverlay
hook provides a simple and flexible way to manage a loading overlay in the application. It allows you to show or hide an overlay with a customizable message, ideal for indicating loading states during asynchronous operations like API calls or data processing.Using the hook
Import and use the
useLoadingOverlay
hook in your components to control the overlay.API
showOverlay(message?: string): void
message
: (Optional) The message to display on the overlay.hideOverlay(): void
Best Practices
hideOverlay
in both.then()
and.catch()
to handle successful and error scenarios.useEffect
cleanup function to hide the overlay.Example Usage
Screenshot