目标:创建一个可重用的OptionFan组件,该组件允许子组件作为ChildButton组件。
问题:无法访问OptionFan(父)组件方法“ShowOptions()”内ChildButton的方法“Flyout()”
在选项风扇组件中:
showOptions = () => {
let animations = this.props.children.map((child, i) => {
this.refs.child.flyOut();
});
Animated.stagger(this.props.staggerDelay, animations).start();
}
renderOptions = () => {
return this.props.children.map((child, i) => {
return <ChildButton ref={child} siblings={this.props.children.length} key={i} icon={} number={i} size={} />
})
}
在ChildButton组件中:
componentDidMount() {
this.props.ref(this);
}
flyOut = () => {
const {number, size} = this.state;
let offset = this.findChildCoordinates(number);
Animated.timing(
this.state.move,
{toValue: offset}
).start();
}
所需方法在代码建议中不可访问,
我的方法有什么不正确?