Skip to content

Commit

Permalink
fix: crash when trying to wiggle duration Infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnartorfis committed Sep 11, 2024
1 parent 76f98f3 commit 3e81b34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions example/src/ToastDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export const ToastDemo: React.FC = () => {
<Button
title="Wiggle toast"
onPress={() => {
if (toastId) {
toast.wiggle(toastId);
}
toast.wiggle('123');
}}
/>
Expand Down Expand Up @@ -312,6 +315,7 @@ export const ToastDemo: React.FC = () => {
const id = toast.success('Infinity toast', {
duration: Infinity,
dismissible: false,
id: 'infinity',
action: {
label: 'Acknowledge',
onClick: () => {
Expand Down
7 changes: 6 additions & 1 deletion src/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ export const Toast = React.forwardRef<ToastRef, ToastProps>(
}, [wiggleSharedValue]);

const wiggleHandler = React.useCallback(() => {
// we can't send Infinity over to the native layer.
if (duration === Infinity) {
return;
}

// reset the duration
timerStart.current = Date.now();
startTimer();
Expand All @@ -131,7 +136,7 @@ export const Toast = React.forwardRef<ToastRef, ToastProps>(
} else {
wiggle();
}
}, [wiggle, wiggleSharedValue, startTimer]);
}, [wiggle, wiggleSharedValue, startTimer, duration]);

React.useImperativeHandle(ref, () => ({
wiggle: wiggleHandler,
Expand Down

0 comments on commit 3e81b34

Please sign in to comment.