【发布时间】:2018-04-25 21:34:31
【问题描述】:
当我从 Text 组件中删除动画类时,这段代码 sn-p 运行良好。但是我不明白为什么在尝试将子组件与动画 api 一起使用时,我无法从子组件调用父组件的函数。
import React from 'react';
import { Animated, TouchableOpacity, StyleSheet, Text, View, Dimensions } from 'react-native';
class Txt extends React.Component {
constructor() {
super()
this.childButton = this.childButton.bind(this);
}
componentWillMount() {
this.position = new Animated.ValueXY({ x: 200, y: 400 });
}
childButton() {
this.props.callback(this.props.id);
}
render() {
return (
<TouchableOpacity onPress={this.childButton}>
<Animated.Text style={{ transform: [{ translateY: this.position.y }] }}>
button
</ Animated.Text >
</TouchableOpacity >
)
}
}
export default class App extends React.Component {
constructor() {
super()
this.parentButton = this.parentButton.bind(this);
}
parentButton(param) {
console.log(param);
}
render() {
return (
<View>
<Txt callback={this.parentButton} id="_3131" />
</View>
);
}
}
【问题讨论】:
标签: javascript reactjs animation react-native ecmascript-6