Pārlūkot izejas kodu

Bugfix: Toast and Snackbar freeze problem fixed.

lfabl 1 nedēļu atpakaļ
vecāks
revīzija
1bb48c1e82

+ 9 - 1
src/components/snackBar/index.tsx

@@ -113,6 +113,8 @@ const SnackBar: FC<ISnackBarProps> = ({
     });
 
     useEffect(() => {
+        let timeout: NodeJS.Timeout;
+
         if(isMeasured) {
             transformAnim.setValue(-contentHeight.current + -top + -spaces.spacingSm);
 
@@ -131,10 +133,16 @@ const SnackBar: FC<ISnackBarProps> = ({
                 })
             ]).start();
 
-            setTimeout(() => {
+            timeout = setTimeout(() => {
                 closeAnimation();
             }, autoCloseDelay);
         }
+
+        return () => {
+            if(timeout) {
+                clearTimeout(timeout);
+            }
+        };
     }, [
         isMeasured
     ]);

+ 5 - 1
src/components/toast/index.tsx

@@ -108,9 +108,13 @@ const Toast: FC<IToastProps> = ({
             })
         ]).start();
 
-        setTimeout(() => {
+        const timeout = setTimeout(() => {
             closeAnimation();
         }, autoCloseDelay);
+
+        return () => {
+            clearTimeout(timeout);
+        };
     }, []);
 
     const closeAnimation = (_onClosed?: (props: {

+ 2 - 3
src/helpers/portalize/Manager.tsx

@@ -60,10 +60,9 @@ export const Manager = forwardRef(({
             {
                 children,
                 key
-            },
-            index: number
+            }
         ) => <View
-            key={`NCoreUIKit-Portal-${key}-${index}`}
+            key={`NCoreUIKit-Portal-${key}`}
             style={[
                 StyleSheet.absoluteFill
             ]}