import React, {Component} from 'react';
import {Text, View, TouchableOpacity} from 'react-native';
export default class Parent extends Component {
render() {
return(
<View>
<Child onRef={this.onRef} />
<TouchableOpacity onClick={this.click} >
<Text>click</Text>
</View>
)
}
// 标记触发的子组件
onRef = (ref) => {
this.child = ref
}
// 调用子组件方法
click = (e) => {
this.child.myName()
}
}
class Child extends Component {
componentDidMount(){
// 父级标记
this.props.onRef(this)
}
// 子组件方法
myName = () =>{
console.log(11111111111111)
}
render() {
return (<View></View>)
}
}