gpt4 book ai didi

Animated.View 的样式 Prop 的 typescript 定义

转载 作者:行者123 更新时间:2023-12-03 18:38:50 26 4
gpt4 key购买 nike

我有一个 Props 的组件接口(interface)扩展 ViewProps来自 React Native,即:

export interface Props extends ViewProps {
// Custom props
}

自然,这扩展了 style支柱。有一个警告,我正在使用 Animated.View并有这样的风格:
style={{
opacity: animationCharacter.interpolate({
inputRange: [0, 1],
outputRange: [0, 1]
}),
transform: [
{
scale: animationCharacter.interpolate({
inputRange: [0, 1],
outputRange: [1.2, 1]
})
}
]
}}

我认为 interpolate调用与来自 ViewProps 的样式类型不兼容,但没有 AnimatedViewProps我可以延长。

这里有解决方案还是我必须设置 style: any ?

最佳答案

@types/react-native开始v0.61.9,可以使用Animated.AnimatedProps :
例如 style 属性:

interface Props {
style?: Animated.AnimatedProps<StyleProp<ViewStyle>>,
}
或获取所有 Prop :
export interface Props extends Animated.AnimatedProps<ViewProps> {
// Custom props
}

关于Animated.View 的样式 Prop 的 typescript 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51521809/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com