React native 如何修复错误:AnimatedValue:尝试将值设置为未定义-反应本机

React native 如何修复错误:AnimatedValue:尝试将值设置为未定义-反应本机,react-native,animation,react-native-android,react-animated,React Native,Animation,React Native Android,React Animated,我想在键盘显示和隐藏时调整徽标的大小。 这是imgStyle.js import {StyleSheet, Dimensions} from 'react-native'; const Height = Dimensions.get('screen'); const height_logo = Height * 0.2; const height_logo_small = Height * 0.6; const IMAGE_HEIGHT = height_l

我想在键盘显示和隐藏时调整徽标的大小。 这是imgStyle.js

 import {StyleSheet, Dimensions} from 'react-native';

    const Height = Dimensions.get('screen');
    const height_logo = Height * 0.2;
    const height_logo_small = Height * 0.6;

    const IMAGE_HEIGHT = height_logo;

    const IMAGE_HEIGHT_SMALL = height_logo_small;
这是主代码。。(非完整代码)

这就是错误:

错误:AnimatedValue:尝试将值设置为未定义


任何人都有此错误或解决了此问题?

图像高度常量不是从imgStyle.js导出的图像高度常量不是从imgStyle.js导出的我在尝试将
动画.Value
设置为布尔值而不是
0
1
时遇到此问题

 import {StyleSheet, Dimensions} from 'react-native';

    const Height = Dimensions.get('screen');
    const height_logo = Height * 0.2;
    const height_logo_small = Height * 0.6;

    const IMAGE_HEIGHT = height_logo;

    const IMAGE_HEIGHT_SMALL = height_logo_small;
需要改变这一点:

// expanded is a boolean var here
const toggleAnim = useRef(new Animated.Value(!expanded)).current;
为此:

// expanded is a boolean var here
const toggleAnim = useRef(new Animated.Value(expanded ? 0 : 1)).current;
必须是一个数字:


(注意:这适用于
Animated.Value
setValue()
,有关详细信息,请参阅上面的链接)

我在尝试将
Animated.Value
设置为布尔值时遇到了此问题,而不是
0
1

需要改变这一点:

// expanded is a boolean var here
const toggleAnim = useRef(new Animated.Value(!expanded)).current;
为此:

// expanded is a boolean var here
const toggleAnim = useRef(new Animated.Value(expanded ? 0 : 1)).current;
必须是一个数字:


(注意:这适用于
Animated.Value
setValue()
,详细信息请参见上面的链接)

您还可以将布尔值包装在
Number()
中,以转换为整数,即
新的Animated.Value(Number(someBoolVal))
。您还可以将布尔值包装在
Number()
中,以转换为整数,即
新的动画.Value(Number(someBoolVal))