question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

withTiming callback unknown error

See original GitHub issue

Description

I’m want to dismiss overlay when the animation is complete, but app crash when provide withTiming callback function. Maybe I do something wrong?

Screenshots

Screenshot_1601389869

Snack or minimal code example

import React, { useEffect } from 'react';
import { View, StyleSheet } from 'react-native';
import { Colors, Spacing } from '@styles';
import Animated, {
    useAnimatedStyle,
    useSharedValue,
    withTiming,
    useDerivedValue,
} from 'react-native-reanimated';
import { Navigation } from 'react-native-navigation';

export const Toast = function ({ componentId }) {
    const progress = useSharedValue(-1);
    const translateY = useDerivedValue(() => {
        return progress.value * 130;
    });
    const animatedStyles = useAnimatedStyle(() => {
        if (progress.value == 0) {
            progress.value = withTiming(-1, null, (isFinished) => {
                if (isFinished) {
                    Navigation.dismissOverlay(componentId);
                }
            });
        }
        return {
            transform: [{ translateY: translateY.value }],
        };
    });
    useEffect(() => {
        progress.value = withTiming(0);
    }, []);
    return (
        <View style={styles.root}>
            <Animated.View style={[styles.toast, animatedStyles]} />
        </View>
    );
};

const styles = StyleSheet.create({
    root: {
        flex: 1,
        backgroundColor:Colors.BLACK,
        paddingHorizontal: Spacing.SPACING_LG,
    },
    toast: {
        height: 130,
        width: '100%',
        borderRadius: Spacing.SPACING_SM,
        backgroundColor: Colors.GRAY_DARK,
    },
});

Toast.options = {
    overlay: {
        interceptTouchOutside: false,
    },
};

Package versions

  • React: “16.13.1”
  • React Native: “0.63.2”
  • React Native Reanimated: “2.0.0-alpha.7”

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

13reactions
karol-bisztygacommented, Nov 2, 2020

Hey! Thanks for the repo 😃 I managed to get it working using new release https://github.com/software-mansion/react-native-reanimated/releases/tag/2.0.0-alpha.8

With runOnJS functionality such code works:

const dismiss = () => {
  Navigation.dismissOverlay(componentId);
};
const animatedStyles = useAnimatedStyle(() => {
  if (progress.value == 0) {
    progress.value = withTiming(-1, null, (isFinished) => {
      if (isFinished) {
        runOnJS(dismiss)();
      }
    });
  }
  return {
    transform: [{translateY: translateY.value}],
  };
});
1reaction
caiphaavcommented, Oct 5, 2020

@terrysahaidak ad 1 - doesn’t matter, can be undefined or null - both work as a passed config object is implicitly converted when checked ad 2 - true, @caiphaav why don’t you try to move this part

if (progress.value == 0) {
            progress.value = withTiming(-1, null, (isFinished) => {
                if (isFinished) {
                    Navigation.dismissOverlay(componentId);
                }
            });
        }

outside of the useAnimatedStyle. This is considered to be a bad practice. Not sure if that would fire this particular error though.

@karol-bisztyga Thank you for your reply. Where I should move this part? To useeffect or another reanimated hook?

Read more comments on GitHub >

github_iconTop Results From Across the Web

withTiming | React Native Reanimated - Software Mansion
The provided function will be called when the animation is complete. In case the animation is cancelled, the callback will receive false as...
Read more >
Error handling with promises - The Modern JavaScript Tutorial
The handler should analyze errors (custom error classes help) and rethrow unknown ones (maybe they are programming mistakes). It's ok not to use ......
Read more >
Plugin Callbacks - Zigbee af API Documentation Silicon Labs
Unknown Special Days Day Id. ... the keep alive process with timing parameters other than the default values. ... Return true on suceess,...
Read more >
expo - React native reanimated , application crashs when call ...
My React native expo application crashing without any error when call function() in withTiming() callback. example :
Read more >
Node API / Logux
error : server error during action processing. fatal : server error during ... Set callbacks for unknown channel subscription. ... Returns WithTime ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found