【发布时间】:2017-12-17 10:01:34
【问题描述】:
这个问题已经困扰我一段时间了,我被卡住了。 当用户点击 Touchable 时,我想为我的文本的颜色属性设置动画。
为此,我使用了一个标签。
我缺少什么来完成这项工作?
到目前为止,这是我的组件:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Text, View, TouchableWithoutFeedback, LayoutAnimation, Animated } from 'react-native';
import { CardSection } from './common';
import * as actions from '../actions';
class ListItem extends Component {
state = {
colorAnim: new Animated.Text('#000')
};
componentWillUpdate() {
LayoutAnimation.easeInEaseOut();
Animated.timing(
this.state.colorAnim,
{
toValue: '#47bed1',
duration: 5000,
}
).start();
}
renderDescription () {
const { library, expanded } = this.props;
if (expanded) {
return (
<CardSection>
<Text style={styles.textStyle}>
{ library.description }
</Text>
</CardSection>
);
}
}
render() {
const { titleStyle } = styles;
const { id, title } = this.props.library;
return (
<TouchableWithoutFeedback
onPress={() => this.props.selectLibrary(id)}
>
<View>
<CardSection>
<Animated.Text
style={{
...titleStyle,
color: this.state.colorAnim
}}
>
{ title }
</Animated.Text>
</CardSection>
{ this.renderDescription() }
</View>
</TouchableWithoutFeedback>
);
}
}
const styles = {
titleStyle: {
fontSize: 18,
paddingLeft: 15
},
textStyle: {
paddingLeft: 18,
paddingRight: 5
}
}
const mapStateToProps = (state, ownProps) => {
const expanded = state.selectedLibraryId === ownProps.library.id;
return {
expanded: expanded
};
};
export default connect(mapStateToProps, actions)(ListItem);
【问题讨论】:
-
我认为你需要使用 react-native Interpolate 来完成这项工作
标签: react-native