即使更改,我也会收到此错误:inputIndex === i? 255:0等于inputIndex === i? “ #ffffff”:“#aaa2d7”。
目的是,当第一个标签处于活动状态时,标题颜色应为白色“ #ffffff”,其他标签应为“#aaa2d7”
const inputRange = props.navigationState.routes.map((x, i) => i);
return (
<View style={{backgroundColor: "#5243af",flexDirection: 'row', height: Metrics.HEIGHT * 0.1, elevation: 0}}>
{ props.navigationState.routes.map((route, i) => {
const color = Animated.color(
Animated.round(
Animated.interpolate(props.position, {
inputRange,
outputRange: inputRange.map(inputIndex =>
inputIndex === i ? "#ffffff" : "#aaa2d7"
),
})
),
0,
0
);
return (
<TouchableOpacity
style={{flex: 1, alignItems: 'center', borderLeftColor: "#9a91d2", borderLeftWidth: 1/* , borderBottomWidth: 3, borderBottomColor "red" */}}
key={i}
onPress={() => {
//this.changeTabs(route.key)
this.setState({ index: i })
}}>
{this._getTabBarIcon(route.key)}
<Animated.Text style={{ color, fontSize: Fonts.moderateScale(15), marginBottom: 10 }}>{route.title.toLocaleUpperCase()}</Animated.Text>
</TouchableOpacity>
);
})}
</View>
);
}
谢谢
答案 0 :(得分:0)
您可以尝试这样的事情。
const scrollY = new Animated.Value(0);
const bgColor = Animated.interpolate(scrollY, {
inputRange: [0, HEADER_HEIGHT],
outputRange: [Animated.color(56, 180, 113, 0), Animated.color(56, 180, 113, 1)]
})