Skip to content

Commit

Permalink
feat : add auto leave props for loader popup
Browse files Browse the repository at this point in the history
  • Loading branch information
hel-axelor committed Jan 26, 2024
1 parent 88981d4 commit d549be5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/apps/stock/src/screens/loader/LoaderScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const LoaderScreen = () => {
timeout={5000}
onSuccess={handleCustomAction}
onError={() => console.warn('An error has occurred!')}
disabled={true}
autoLeave={true}
/>
</View>
</Screen>
Expand Down
23 changes: 19 additions & 4 deletions packages/core/src/components/templates/Loader/LoaderPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface LoaderPopupProps {
onError: () => void;
timeout: number;
disabled: boolean;
autoLeave: boolean;
}

const LoaderPopup = ({
Expand All @@ -45,6 +46,7 @@ const LoaderPopup = ({
onError,
timeout = 100,
disabled = false,
autoLeave = false,
}: LoaderPopupProps) => {
const navigation = useNavigation();
const I18n = useTranslator();
Expand All @@ -55,11 +57,11 @@ const LoaderPopup = ({
const {loading, listener} = useLoaderListner({
process,
onSuccess: () => {
setShowPopup(false);
showPopup && setShowPopup(false);
!disabled && onSuccess();
},
onError: () => {
setShowPopup(false);
showPopup && setShowPopup(false);
!disabled && onError();
},
});
Expand All @@ -86,13 +88,26 @@ const LoaderPopup = ({

timeoutRef.current = setTimeout(() => {
setActivityIndicator(false);
setShowPopup(true);

if (autoLeave && loading) {
handleGoBack();
} else {
setShowPopup(true);
}
}, timeout);

return () => {
clearTimeout(timeoutRef.current);
};
}, [timeout, loading, showPopup, setActivityIndicator, setShowPopup]);
}, [
timeout,
loading,
showPopup,
autoLeave,
setActivityIndicator,
setShowPopup,
handleGoBack,
]);

if (!loading || !showPopup) {
return null;
Expand Down

0 comments on commit d549be5

Please sign in to comment.