Skip to content

Commit

Permalink
feat: add props on Loader to force user to leave screen (#379)
Browse files Browse the repository at this point in the history
* RM#73991
  • Loading branch information
hel-axelor authored and lme-axelor committed May 30, 2024
1 parent bde9cc3 commit 17870f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/apps/stock/src/screens/loader/LoaderScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const LoaderScreen = () => {
onSuccess={handleSuccessAction}
onError={handleErrorAction}
disabled={false}
autoLeave={true}
/>
</View>
</Screen>
Expand Down
15 changes: 13 additions & 2 deletions packages/core/src/components/templates/Loader/LoaderPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface LoaderPopupProps {
onError: () => void;
start?: boolean;
disabled?: boolean;
autoLeave?: boolean;
timeout?: number;
}

Expand All @@ -47,6 +48,7 @@ const LoaderPopup = ({
onError,
start = false,
disabled = false,
autoLeave = false,
timeout = 100,
}: LoaderPopupProps) => {
const navigation = useNavigation();
Expand Down Expand Up @@ -87,15 +89,24 @@ const LoaderPopup = ({

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

autoLeave ? handleNotifyMe() : setShowPopup(true);
}, timeout);
}

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

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

0 comments on commit 17870f4

Please sign in to comment.