【发布时间】:2020-08-29 07:39:39
【问题描述】:
我正在尝试将标题后退按钮的颜色从带有白色箭头图标的灰色背景设置为带有黑色箭头图标的白色背景,以响应本机反应导航 5。
我尝试执行以下操作,但它正在抛出 RangeError: Maximum call stack size exceeded.
const yOffset = useRef(new Animated.Value(0)).current;
const backButtonBackgroundColorAnimation = yOffset.interpolate({
inputRange: [0, 130],
outputRange: ['rgba(0,0,0,0.4)', 'rgba(0,0,0,0)'], // gray transparent to transparent
extrapolate: "clamp"
});
const backArrowColorAnimation = yOffset.interpolate({
inputRange: [0, 130],
outputRange: ['rgb(255,255,255)', 'rgb(0,0,0)'], // white to black
extrapolate: "clamp"
});
import {Icon} from 'react-native-elements';
headerLeft: (props) => (
<Animated.View style={{backgroundColor: backButtonOpacity}} >
<Icon
name='arrowleft'
type='antdesign'
color='white'
size={24}
containerStyle={{ backgroundColor:backButtonBackgroundColorAnimation, color:backArrowColorAnimation, borderRadius:500, padding: 5, marginLeft:10}}
{...props}
onPress={() => {
navigation.goBack();
}}
/>
</Animated.View>
)
<Animated.ScrollView
onScroll={Animated.event(
[
{
nativeEvent: {
contentOffset: {
y: yOffset,
},
},
},
],
{ useNativeDriver: false }
)}
scrollEventThrottle={16}
>
【问题讨论】:
-
Icon组件从何而来?
-
您将背景颜色设置为 backButtonOpacity,这似乎是错误的,因为不透明度和颜色不一样。
-
当您在样式 color:backArrowColorAnimation 中设置颜色时,这似乎是错误的,您应该在
上设置颜色
标签: react-native react-navigation-v5