我正在使用React Navigation和React Native Animatable,两者都很棒。
是否可以与不是其子级的另一个React组件进行交互?像下面这样。我收到错误
“不变违规:React.Children.only预期会收到一个 反应元素孩子。”
handleViewRef = ref => this.view = ref;
bounce = () => this.view.bounce(800).then(endState =>
console.log(endState.finished ? 'bounce finished' : 'bounce cancelled'));
render(){
return (
<TouchableWithoutFeedback onPress={this.bounce}>
</TouchableWithoutFeedback>
<Animatable.View ref={this.handleViewRef}>
<Text>Bounce me!</Text>
</Animatable.View>
)
}
假设我要在导航主视图时进行导航,这样做很酷:
<TouchableHighlight onPress={() => this.props.navigation.navigate('Home')} ><Text>Back</Text></TouchableHighlight>