【发布时间】:2020-10-18 07:20:50
【问题描述】:
下面的代码是用TransformAnimation渲染一个Touchable按钮。
const { scrollY, headerScrollDistance } = this.state;
const profileImageTranslateX = scrollY.interpolate({
inputRange: [0, headerScrollDistance],
outputRange: [0, -(ScreenWidth /2) + 32],
extrapolate: 'clamp',
});
const profileImageTranslateY = scrollY.interpolate({
inputRange: [0, headerScrollDistance],
outputRange: [0, -11],
extrapolate: 'clamp',
});
const profileImageScale = scrollY.interpolate({
inputRange: [0, headerScrollDistance / 2, headerScrollDistance],
outputRange: [1, 0.8, 0.6],
extrapolate: 'clamp',
});
return (
<Animated.View
style={[
Styles.animatedView.profileStyle,
{
transform: [
{ translateX: profileImageTranslateX },
{ translateY: profileImageTranslateY },
{ scale: profileImageScale }
]
}
]}
>
<TouchableOpacity activeOpacity={0.5} onPress={() => this.props.history.push('./profilePhotoChanger')}>
<ImageComp profileImageUrl={profileimageurl} imageStyle={Styles.homePageImageStyle} />
</TouchableOpacity>
</Animated.View>
);
随着页面滚动,Animation 应用于 Touchable 按钮。未应用变换动画时,按钮按预期工作。但是在应用动画时不起作用。如果页面恢复正常状态(即向后滚动),则按钮按预期工作。
react-native 中的正常行为是 TouchableOpacity's onPress 在应用动画时不起作用吗?还是我的代码有问题?
【问题讨论】:
标签: react-native animation transform touchableopacity