React-native 导航器 goBack()后刷新页面
Example
import React, { Component } from "react";
import { Text, View, TouchableOpacity } from "react-native";
class A extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
}
refreshScreen=()=>{
this.refreshData();
}
goBScreen() {
const { navigation } = this.props;
navigation.navigate("B", {
refresh:()=>{
this.refreshScreen();
},
});
}
render() {
return (
<View>
<TouchableOpacity onPress={this.goBScreen.bind(this)}>
<Text>跳转去 B 页面</Text>
</TouchableOpacity>
</View>
)
}
}
import React, { Component } from "react";
import { Text, View, TouchableOpacity } from "react-native";
class B extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
this.refreshData();
}
goBack() {
this.props.navigation.goBack();
this.props.route.params.refresh();
}
render() {
return (
<View>
<TouchableOpacity onPress={this.goBack.bind(this)}>
<Text>编辑完数据 返回 A 页面</Text>
</TouchableOpacity>
</View>
)
}
}