React Native 如何获得参考按钮由纸复活?

bbuxkriu  于 2023-10-22  发布在  React
关注(0)|答案(1)|浏览(102)

如何获得ref从按钮由纸为复活?
我的代码:

import { Button } from 'react-native-paper';
import Animated from 'react-native-reanimated';
    
    ...
    
    const MyView = React.forwardRef((props, ref) => {
        return <Button ref={ref} {...props} />;
    });

    const MyAnimatedView = Animated.createAnimatedComponent(MyView);

我得到一个错误:Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

nbysray5

nbysray51#

编辑:这不是解决问题的直接方法,但我没有找到其他方法。

好吧,我不得不从头开始写我自己的组件。
大概是这样的:

import { Pressable, Text } from "react-native";
import Animated from "react-native-reanimated";

...

<Pressable>
    <Animated.View style={animatedViewStyle}>
        <Text>Button</Text>
    </Animated.View>
</Pressable>

相关问题